package com.qmth.distributed.print.api;

import com.qmth.boot.api.constant.ApiConstant;
import com.qmth.distributed.print.business.bean.params.ObeCourseOutlineParam;
import com.qmth.distributed.print.business.bean.result.DictionaryResult;
import com.qmth.distributed.print.business.bean.result.EditResult;
import com.qmth.distributed.print.business.bean.result.ObeCourseBasicInfoResult;
import com.qmth.distributed.print.business.bean.result.ObeCourseOutlineResult;
import com.qmth.distributed.print.business.service.ObeCourseOutlineService;
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
import com.qmth.teachcloud.common.contant.SystemConstant;
import com.qmth.teachcloud.common.enums.log.OperationTypeEnum;
import com.qmth.teachcloud.common.util.Result;
import com.qmth.teachcloud.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * <p>
 * 课程大纲表 前端控制器
 * </p>
 *
 * @author CaoZixuan
 * @since 2024-06-05
 */
@Api(tags = "课程大纲管理controller")
@RestController
@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_OBE + "/course_outline")
public class ObeCourseOutlineController {

    @Resource
    private ObeCourseOutlineService obeCourseOutlineService;

    @ApiOperation(value = "课程大纲-查询")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = ObeCourseOutlineResult.class) })
    public Result findObeCourseOutlinePage(@ApiParam(value = "专业id") @RequestParam(required = false) String professionalId,
            @ApiParam(value = "培养方案id") @RequestParam(required = false) String cultureProgramId,
            @ApiParam(value = "课程id") @RequestParam(required = false) String courseId,
            @ApiParam(value = "课程大纲名称（模糊查询）") @RequestParam(required = false) String courseOutlineName,
            @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
            @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {

        return ResultUtil.ok(obeCourseOutlineService.findObeCourseOutlinePage(SystemConstant.convertIdToLong(professionalId),
                SystemConstant.convertIdToLong(cultureProgramId), SystemConstant.convertIdToLong(courseId),
                courseOutlineName, pageNumber, pageSize));
    }

    @ApiOperation(value = "课程考核设置-查询")
    @RequestMapping(value = "/assessment_setting_page", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = ObeCourseOutlineResult.class) })
    public Result findAssessmentSettingPage(@ApiParam(value = "专业id") @RequestParam(required = false) String professionalId,
            @ApiParam(value = "培养方案id") @RequestParam(required = false) String cultureProgramId,
            @ApiParam(value = "课程id") @RequestParam(required = false) String courseId,
            @ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) Integer pageNumber,
            @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) Integer pageSize) {

        return ResultUtil.ok(obeCourseOutlineService.findObeCourseOutlinePage(SystemConstant.convertIdToLong(professionalId),
                SystemConstant.convertIdToLong(cultureProgramId), SystemConstant.convertIdToLong(courseId), null, pageNumber, pageSize));
    }

    @ApiOperation(value = "课程大纲-保存")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "创建成功", response = EditResult.class) })
    @OperationLogDetail(detail = "新增课程大纲，参数[{{obeCourseOutlineParam}}]", operationType = OperationTypeEnum.ADD)
    public Result saveObeCourseOutline(@Valid @RequestBody ObeCourseOutlineParam obeCourseOutlineParam, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        obeCourseOutlineService.saveObeCourseOutline(obeCourseOutlineParam);
        return ResultUtil.ok();
    }

    @ApiOperation(value = "课程大纲-删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "删除成功", response = EditResult.class) })
    @OperationLogDetail(operationType = OperationTypeEnum.DELETE, detail = "删除操作，课程大纲id：[{{id}}]")
    public Result deleteObeCourseOutline(@ApiParam(value = "选择的要删除的课程大纲id", required = true) @RequestParam String id) {
        obeCourseOutlineService.removeObeCourseOutline(SystemConstant.convertIdToLong(id));
        return ResultUtil.ok();
    }

    @ApiOperation(value = "课程考核设置-删除")
    @RequestMapping(value = "/assessment_setting_delete", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "删除成功", response = EditResult.class) })
    @OperationLogDetail(operationType = OperationTypeEnum.DELETE, detail = "删除操作，课程大纲id：[{{id}}]")
    public Result deleteAssessmentSetting(@ApiParam(value = "选择的要删除的课程大纲id", required = true) @RequestParam String id) {
        obeCourseOutlineService.removeAssessmentSetting(SystemConstant.convertIdToLong(id));
        return ResultUtil.ok();
    }

    @ApiOperation(value = "课程大纲-课程基本信息")
    @RequestMapping(value = "/course_basic_info", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = ObeCourseBasicInfoResult.class) })
    public Result findCourseBasicInfo(@ApiParam(value = "课程大纲id", required = true) @RequestParam String obeCourseOutlineId) {
        return ResultUtil.ok(obeCourseOutlineService.findCourseBasicInfo(SystemConstant.convertIdToLong(obeCourseOutlineId)));
    }

    @ApiOperation(value = "课程大纲-查询课程权重设置状态")
    @RequestMapping(value = "/find_course_weight_setting_status", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = Result.class) })
    public Result findCourseWeightSettingStatus(@ApiParam(value = "课程大纲id", required = true) @RequestParam String obeCourseOutlineId) {
        return ResultUtil.ok(obeCourseOutlineService.findCourseWeightSettingStatus(SystemConstant.convertIdToLong(obeCourseOutlineId)));
    }

    @ApiOperation(value = "课程大纲-查询可选择的培养方案")
    @RequestMapping(value = "/can_choose_culture_program", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = DictionaryResult.class) })
    public Result findCanChooseCultureProgram() {
        return ResultUtil.ok(obeCourseOutlineService.findCanChooseCultureProgram());
    }

    @ApiOperation(value = "课程大纲-查询可选择的课程")
    @RequestMapping(value = "/can_choose_course", method = RequestMethod.POST)
    @ApiResponses({ @ApiResponse(code = 200, message = "查询成功", response = DictionaryResult.class) })
    public Result findCanChooseCourse(@ApiParam(value = "培养方案id", required = true) @RequestParam String cultureProgramId) {
        return ResultUtil.ok(obeCourseOutlineService.findCanChooseCourse(SystemConstant.convertIdToLong(cultureProgramId)));
    }
}
