package jnpf.cultivate.controller.web.course;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.service.FtbCultivateCourseChapterService;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.dto.course.FtbCultivateCourseChapterDTO;
import jnpf.model.cultivate.dto.course.FtbCultivateCourseChapterUpdateDTO;
import jnpf.model.cultivate.po.course.FtbCultivateCourse;
import jnpf.model.cultivate.vo.course.web.FtbCultivateCourseChapterDetailsVO;
import jnpf.model.cultivate.vo.course.web.FtbCultivateCourseChapterVO;
import jnpf.model.cultivate.vo.course.web.FtbCultivateCourseTypeVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
* web课程章节模块
*
* @author xxxxx
*/
@RestController
@RequestMapping("/web/ftb-cultivate-course-chapter")
public class FtbCultivateCourseChapterController {

    @Resource
    private FtbCultivateCourseChapterService ftbCultivateCourseChapterService;

    /**
     * 添加课程章节
     *
     * @param ftbCultivateCourseDTO 课程章节参数
     * @return {@link ActionResult}<{@link FtbCultivateCourse}>
     */
    @PostMapping("/add")
    public ActionResult add(@Validated @RequestBody FtbCultivateCourseChapterDTO ftbCultivateCourseDTO) {
        ftbCultivateCourseChapterService.add(ftbCultivateCourseDTO);
        return ActionResult.success();
    }

    /**
     * 删除课程章节
     *
     * @param id 课程主键id
     * @return {@link ActionResult}
     */
    @DeleteMapping("/{id}")
    public ActionResult delete(@PathVariable("id") String id) {
        ftbCultivateCourseChapterService.delete(id);
        return ActionResult.success();
    }

    /**
     * 更新课程信息章节
     *
     * @param ftbCultivateCourseDTO 课程章节参数
     * @return {@link ActionResult}
     */
    @PutMapping("/update")
    public ActionResult update(@Validated @RequestBody FtbCultivateCourseChapterUpdateDTO ftbCultivateCourseDTO) {
        ftbCultivateCourseChapterService.updateChapter(ftbCultivateCourseDTO);
        return ActionResult.success();
    }

    /**
     * 课程章节分页列表
     *
     * @param cultivatePage 分页参数
     * @param courseId 课程id，必传
     * @return {@link ActionResult}<{@link Page}<{@link FtbCultivateCourseTypeVO}>>
     */
    @GetMapping("/list")
    public ActionResult<PageListVO<FtbCultivateCourseChapterVO>> list(CultivatePage cultivatePage, String courseId) {
        Page<FtbCultivateCourseChapterVO> page = cultivatePage.coverCultivatePage();
        page = ftbCultivateCourseChapterService.queryList(page, courseId);
        return ActionResult.success(CultivatePage.coverPageList(page));
    }

    /**
     * 课程章节详情-编辑时回显调用
     *
     * @param id 课程主键id
     * @return {@link ActionResult}<{@link FtbCultivateCourse}>
     */
    @GetMapping("/details/{id}")
    public ActionResult<FtbCultivateCourseChapterDetailsVO> courseDetails(@PathVariable("id") String id) {
        FtbCultivateCourseChapterDetailsVO result = ftbCultivateCourseChapterService.courseDetails(id);
        return ActionResult.success(result);
    }

}
