package org.dromara.system.controller.course;

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.system.domain.vo.CourseTableTimeVo;
import org.dromara.system.domain.bo.CourseTableTimeBo;
import org.dromara.system.service.ICourseTableTimeService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 课程-时间
 *
 * @author Lion Li
 * @date 2023-08-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/course/time")
public class CourseTableTimeController extends BaseController {

    private final ICourseTableTimeService courseTableTimeService;

    /**
     * 查询课程-时间列表
     */
    @SaCheckPermission("course:time:list")
    @GetMapping("/list")
    public TableDataInfo<CourseTableTimeVo> list(CourseTableTimeBo bo, PageQuery pageQuery) {
        return courseTableTimeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出课程-时间列表
     */
    @SaCheckPermission("course:time:export")
    @Log(title = "课程-时间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(CourseTableTimeBo bo, HttpServletResponse response) {
        List<CourseTableTimeVo> list = courseTableTimeService.queryList(bo);
        ExcelUtil.exportExcel(list, "课程-时间", CourseTableTimeVo.class, response);
    }

    /**
     * 获取课程-时间详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("course:time:query")
    @GetMapping("/{id}")
    public R<CourseTableTimeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(courseTableTimeService.queryById(id));
    }

    /**
     * 新增课程-时间
     */
    @SaCheckPermission("course:time:add")
    @Log(title = "课程-时间", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody CourseTableTimeBo bo) {
        return toAjax(courseTableTimeService.insertByBo(bo));
    }

    /**
     * 修改课程-时间
     */
    @SaCheckPermission("course:time:edit")
    @Log(title = "课程-时间", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody CourseTableTimeBo bo) {
        return toAjax(courseTableTimeService.updateByBo(bo));
    }

    /**
     * 删除课程-时间
     *
     * @param ids 主键串
     */
    @SaCheckPermission("course:time:remove")
    @Log(title = "课程-时间", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(courseTableTimeService.deleteWithValidByIds(List.of(ids), true));
    }
}
