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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.school.secondClass.EduSecondClassCourseContent;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.dto.secondClass.ListCourseContentDTO;
import com.yida.data.school.secondClass.service.EduSecondClassCourseContentService;
import com.yida.data.school.vo.secondClass.CourseContentVO;
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/content")
@RequiredArgsConstructor
public class EduSecondClassCourseContentController {

    private final EduSecondClassCourseContentService eduSecondClassCourseContentService;

    @ApiOperation("查询课程内容列表")
    @GetMapping("/listContentPage")
    public ResultBean<IPage<CourseContentVO>> listContentPage(ListCourseContentDTO dto) {
        return ResultBean.buildSuccess(eduSecondClassCourseContentService.listContentPage(dto));
    }

    @ApiOperation("重命名课程内容")
    @GetMapping("/renameContent")
    public ResultBean renameContent(Long id, String name) {
        eduSecondClassCourseContentService
            .update(Wrappers.<EduSecondClassCourseContent>lambdaUpdate().eq(EduSecondClassCourseContent::getId, id)
                .set(EduSecondClassCourseContent::getName, name));
        return ResultBean.buildSuccess();
    }

    @ApiOperation("上传课程内容")
    @PostMapping("/saveContent")
    public ResultBean saveContent(@RequestBody EduSecondClassCourseContent content) {
        content.setDeptId(FebsUtil.getTopDeptId());
        eduSecondClassCourseContentService.saveContent(content);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("删除课程内容")
    @GetMapping("/delContent")
    public ResultBean delCOntent(Long id) {
        eduSecondClassCourseContentService.removeById(id);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("改变讲师")
    @GetMapping("/changeLecturer")
    public ResultBean changeLecturer(Long id, Long lecturerId) {
        eduSecondClassCourseContentService.changeLecturer(id, lecturerId);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("修改课程内容排序")
    @GetMapping("/changeSort")
    public ResultBean changeSort(Long id, @ApiParam("排序变更步长，正数向后，负数向前") Integer sortStep) {
        eduSecondClassCourseContentService.changeSort(id, sortStep);
        return ResultBean.buildSuccess();
    }
}
