package com.zhongzheng.controller.course;

import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.core.page.TableDataInfo;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.common.utils.ServletUtils;
import com.zhongzheng.framework.web.service.WxTokenService;
import com.zhongzheng.modules.course.bo.CourseAddBo;
import com.zhongzheng.modules.course.bo.CourseEditBo;
import com.zhongzheng.modules.course.bo.CourseMenuQueryBo;
import com.zhongzheng.modules.course.bo.CourseQueryBo;
import com.zhongzheng.modules.course.service.ICourseChapterSectionService;
import com.zhongzheng.modules.course.service.ICourseMenuService;
import com.zhongzheng.modules.course.service.ICourseModuleChapterService;
import com.zhongzheng.modules.course.service.ICourseService;
import com.zhongzheng.modules.course.vo.*;
import com.zhongzheng.modules.goods.vo.GoodsUserVo;
import com.zhongzheng.modules.goods.vo.GoodsVo;
import com.zhongzheng.modules.user.entity.ClientLoginUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程Controller
 *
 * @author hjl
 * @date 2021-10-09
 */
@Api(value = "课程控制器", tags = {"课程管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/course")
public class CourseController extends BaseController {

    private final ICourseService iCourseService;
    private final WxTokenService wxTokenService;
    private final ICourseModuleChapterService iCourseModuleChapterService;
    private final ICourseMenuService iCourseMenuService;
    private final ICourseChapterSectionService iCourseChapterSectionService;

    /**
     * 查询课程列表
     */
    @ApiOperation("查询商品下的课程列表")
    @GetMapping("/courseList")
    public TableDataInfo<CourseUserVo> courseList(CourseQueryBo bo) {
        startPage();
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<CourseUserVo> list = iCourseService.courseList(bo);
        return getDataTable(list);
    }

    /**
     * 获取课程详细信息
     */
    @ApiOperation("获取课程详细信息")
    @GetMapping("/{courseId}")
    public AjaxResult<CourseUserVo> getCourseUserVoInfo(@PathVariable("courseId" ) Long courseId) {
        return AjaxResult.success(iCourseService.getCourseUserVoInfo(courseId));
    }

    /**
     * 查询课程列表
     */
    @ApiOperation("查询用户拥有的商品")
    @GetMapping("/goodsList")
    public TableDataInfo<GoodsUserVo> goodsList(CourseQueryBo bo) {
        startPage();
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<GoodsUserVo> list = iCourseService.goodsList(bo);
        return getDataTable(list);
    }

    /**
     * 查询课程目录结构列表
     */
    @ApiOperation("查询课程目录结构列表")
    @GetMapping("/menuList")
    public TableDataInfo<CourseUserMenuVo> menuList(CourseMenuQueryBo bo) {
        startPage();
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<CourseUserMenuVo> list = iCourseMenuService.menuList(bo);
        return getDataTable(list);
    }


    @ApiOperation("查询模块与章关系列表")
    @GetMapping("/chapterList")
    public AjaxResult<List<CourseUserModuleChapterVo>> chapterList(CourseMenuQueryBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<CourseUserModuleChapterVo> list = iCourseModuleChapterService.chapterList(bo);
        return AjaxResult.success(list);
    }

    /**
     * 查询章与节关系列表
     */
    @ApiOperation("查询章与节关系列表+章卷同级展示")
    @GetMapping("/sectionList")
    public AjaxResult<List<CourseUserChapterSectionVo>> sectionList(CourseMenuQueryBo bo) {
        ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
        bo.setUserId(loginUser.getUser().getUserId());
        List<CourseUserChapterSectionVo> list = iCourseChapterSectionService.sectionList(bo);
        return AjaxResult.success(list);
    }
}
