package com.yida.data.school.secondClass.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.school.secondClass.EduSecondClassCourse;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.dto.secondClass.ListCourseDTO;
import com.yida.data.school.secondClass.service.EduSecondClassCourseService;
import com.yida.data.school.vo.secondClass.CourseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Controller
 *
 * @author zhanghaijun
 * @date 2022-04-11 11:09:15
 */
@Api(tags = "第二课堂-课程")
@Slf4j
@Validated
@RestController
@RequestMapping("/secondClass/course")
@RequiredArgsConstructor
public class EduSecondClassCourseController {

    private final EduSecondClassCourseService eduSecondClassCourseService;

    @ApiOperation("分页查询课程列表")
    @GetMapping("/listCoursePage")
    public ResultBean<IPage<CourseVO>> listCoursePage(ListCourseDTO dto) {
        dto.setDeptId(FebsUtil.getTopDeptId());
        return ResultBean.buildSuccess(eduSecondClassCourseService.listCoursePage(dto));
    }

    @ApiOperation("保存课程")
    @PostMapping("/saveCourse")
    public ResultBean saveCourse(@RequestBody EduSecondClassCourse course) {
        course.setDeptId(FebsUtil.getTopDeptId());
        eduSecondClassCourseService.saveOrUpdate(course);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("删除课程")
    @GetMapping("/delCourse")
    public ResultBean delCourse(Long id) {
        eduSecondClassCourseService.delCourse(id);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("更改课程发布状态")
    @GetMapping("/changeStatus")
    public ResultBean changeStatus(Long id, @ApiParam("0-下架，1-发布") Integer status,
        @RequestParam(required = false) Long subjectId) {
        eduSecondClassCourseService.changeStatus(id, status, subjectId);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("查询课程详情")
    @GetMapping("/getInfo")
    public ResultBean<CourseVO> getInfo(Long id) {
        return ResultBean.buildSuccess(eduSecondClassCourseService.getInfo(id));
    }

    @ApiOperation("更改课程推荐状态")
    @GetMapping("/changeRecommend")
    public ResultBean changeRecommend(Long id, @ApiParam("0-不推荐，1-推荐") Integer status) {
        eduSecondClassCourseService.changeRecommend(id, status);
        return ResultBean.buildSuccess();
    }
}
