package org.dromara.app.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.app.domain.vo.AppScheduleDetailVo;
import org.dromara.app.domain.bo.AppScheduleDetailBo;
import org.dromara.app.service.IAppScheduleDetailService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 排程详情
 *
 * @author Lion Li
 * @date 2026-04-25
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/scheduleDetail")
public class AppScheduleDetailController extends BaseController {

    private final IAppScheduleDetailService appScheduleDetailService;

    /**
     * 查询排程详情列表
     */
    @SaCheckPermission("app:scheduleDetail:list")
    @GetMapping("/list")
    public TableDataInfo<AppScheduleDetailVo> list(AppScheduleDetailBo bo, PageQuery pageQuery) {
        return appScheduleDetailService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出排程详情列表
     */
    @SaCheckPermission("app:scheduleDetail:export")
    @Log(title = "排程详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppScheduleDetailBo bo, HttpServletResponse response) {
        List<AppScheduleDetailVo> list = appScheduleDetailService.queryList(bo);
        ExcelUtil.exportExcel(list, "排程详情", AppScheduleDetailVo.class, response);
    }

    /**
     * 获取排程详情详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("app:scheduleDetail:query")
    @GetMapping("/{id}")
    public R<AppScheduleDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(appScheduleDetailService.queryById(id));
    }

    /**
     * 新增排程详情
     */
    @SaCheckPermission("app:scheduleDetail:add")
    @Log(title = "排程详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppScheduleDetailBo bo) {
        return toAjax(appScheduleDetailService.insertByBo(bo));
    }

    /**
     * 修改排程详情
     */
    @SaCheckPermission("app:scheduleDetail:edit")
    @Log(title = "排程详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppScheduleDetailBo bo) {
        return toAjax(appScheduleDetailService.updateByBo(bo));
    }

    /**
     * 删除排程详情
     *
     * @param ids 主键串
     */
    @SaCheckPermission("app:scheduleDetail:remove")
    @Log(title = "排程详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(appScheduleDetailService.deleteWithValidByIds(List.of(ids), true));
    }
}
