package jnpf.cultivate.controller.web.coursepackage;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.service.FtbCultivateCoursePackageService;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.dto.coursepackage.FtbCultivateCoursePackageAddDTO;
import jnpf.model.cultivate.dto.coursepackage.FtbCultivateCoursePackageQueryDTO;
import jnpf.model.cultivate.dto.coursepackage.FtbCultivateCoursePackageUpdateDTO;
import jnpf.model.cultivate.vo.coursepackage.FtbCultivateCoursePackageDetailsVO;
import jnpf.model.cultivate.vo.coursepackage.FtbCultivateCoursePackagePageVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * web课程包模块
 *
 * @author wcx
 */
@RestController
@RequestMapping("/web/ftb-cultivate-course-package")
public class FtbCultivateCoursePackageController {

    @Resource
    private FtbCultivateCoursePackageService ftbCultivateCoursePackageService;


    /**
     * 添加课程包
     *
     * @param ftbCultivateCoursePackageAddDTO
     * @return {@link ActionResult }
     */
    @PostMapping("/add")
    public ActionResult add(@RequestBody @Validated FtbCultivateCoursePackageAddDTO ftbCultivateCoursePackageAddDTO) {
        ftbCultivateCoursePackageService.add(ftbCultivateCoursePackageAddDTO);
        return ActionResult.success();
    }

    /**
     * 更新课程包
     */
    @PutMapping("/update")
    public ActionResult updateCoursePackage(@RequestBody @Validated FtbCultivateCoursePackageUpdateDTO ftbCultivateCoursePackageUpdateDTO) {
        ftbCultivateCoursePackageService.updateCoursePackage(ftbCultivateCoursePackageUpdateDTO);
        return ActionResult.success();
    }

    /**
     * 删除课程包
     *
     * @param id 课程包id(必传)
     * @return {@link ActionResult }
     */
    @DeleteMapping("/delete/{id}")
    public ActionResult deleteCoursePackage(@PathVariable("id") String id) {
        ftbCultivateCoursePackageService.deleteCoursePackage(id);
        return ActionResult.success();
    }

    /**
     * 课程包列表
     */
    @GetMapping("/list")
    public ActionResult<PageListVO<FtbCultivateCoursePackagePageVO>> list(CultivatePage cultivatePage, FtbCultivateCoursePackageQueryDTO ftbCultivateCoursePackageQueryDTO) {
        Page<FtbCultivateCoursePackagePageVO> page = cultivatePage.coverCultivatePage("a.F_Id");
        page = ftbCultivateCoursePackageService.pagingQuery(page, ftbCultivateCoursePackageQueryDTO);
        PageListVO<FtbCultivateCoursePackagePageVO> result = CultivatePage.coverPageList(page);
        return ActionResult.success(result);
    }

    /**
     * 课程包详情-课程列表分页
     *
     * @param id 课程包id(必传)
     * @return
     */
    @GetMapping("/details/{id}")
    public ActionResult<List<FtbCultivateCoursePackageDetailsVO>> get(@PathVariable("id") String id) {
        List<FtbCultivateCoursePackageDetailsVO> result = ftbCultivateCoursePackageService.get(id);
        return ActionResult.success(result);
    }

    /**
     * 查询课程包课程
     *
     * @param coursePackageIds 课程包主键id集合
     * @return {@link ActionResult }
     */
    @PostMapping("/query-course-package-courses")
    public ActionResult<List<FtbCultivateCoursePackageDetailsVO>> queryCoursePackageCourses(@RequestBody List<String> coursePackageIds) {
        if (CollUtil.isEmpty(coursePackageIds)) {
            throw new RuntimeException("请勾选课程包");
        }
        List<FtbCultivateCoursePackageDetailsVO> result = ftbCultivateCoursePackageService.queryCoursePackageCourses(coursePackageIds);
        return ActionResult.success(result);
    }

}
