package com.yonge.cooleshow.website.controller.open;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.cooleshow.biz.dal.dto.search.VideoLessonGroupSearch;
import com.yonge.cooleshow.biz.dal.dto.search.VideoLessonSearch;
import com.yonge.cooleshow.biz.dal.enums.AuditStatusEnum;
import com.yonge.cooleshow.biz.dal.enums.AuthStatusEnum;
import com.yonge.cooleshow.biz.dal.service.AppVersionInfoService;
import com.yonge.cooleshow.biz.dal.service.VideoLessonGroupDetailService;
import com.yonge.cooleshow.biz.dal.service.VideoLessonGroupService;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonGroupDetailVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonGroupVo;
import com.yonge.cooleshow.biz.dal.vo.VideoLessonStudentVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.base.page.PageInfo;
import com.yonge.toolset.mybatis.support.PageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

import java.util.List;

/**
 * 视频课基本信息表 web 控制层
 * @author yzp
 * @date 2022-03-26 00:21:46
 * @version v1.0
 **/
@RestController
@RequestMapping("/open/videoLessonGroup")
@Api(tags = "开放视频课接口")
public class OpenVideoGroupController extends BaseController {
    @Autowired
    private VideoLessonGroupService videoLessonGroupService;
    @Autowired
    private VideoLessonGroupDetailService videoLessonGroupDetailService;

    @Autowired
    private AppVersionInfoService appVersionInfoService;
    /**
    * @Description: 查询视频课组
    * @Author: cy
    * @Date: 2022/3/31
    */
    @ApiOperation(value = "查询视频课组")
    @PostMapping(value = "/page")
    public HttpResponseResult<PageInfo<VideoLessonGroupVo>> page(@RequestBody VideoLessonGroupSearch query) {
        query.setAuditStatus(AuthStatusEnum.PASS.getCode());

        // 检查app版本
        query.setAuditVersion(appVersionInfoService.getAppAuditVersion(query.getPlatform(),query.getVersion()));
        IPage<VideoLessonGroupVo> pages = videoLessonGroupService.selectPage(PageUtil.getPage(query), query);
        return succeed(PageUtil.pageInfo(pages));
    }

    /**
     * @Description: 根据组id查询视频课&视频课组
     * @Author: cy
     * @Date: 2022/4/2
     */
    @ApiOperation(value = "根据组id查询视频课&视频课组")
    @GetMapping(value="/selectVideoLesson")
    public HttpResponseResult<VideoLessonStudentVo> selectVideoLesson(@NotNull(message = "视频组id不能为空") Long groupId) {
        return succeed(videoLessonGroupService.selectVideoLesson(groupId));
    }

    /**
     * @Description: 根据视频课组id查详情
     * @Author: cy
     * @Date: 2022/6/27
     */
    @ApiOperation(value = "查询视频课", httpMethod = "POST", consumes = "application/json", produces = "application/json")
    @PostMapping(value = "/info/page", consumes = "application/json", produces = "application/json")
    public HttpResponseResult<PageInfo<VideoLessonGroupDetailVo>> page(@RequestBody VideoLessonSearch query) {
        IPage<VideoLessonGroupDetailVo> pages = videoLessonGroupDetailService.selectPage(PageUtil.getPage(query), query);
        return succeed(PageUtil.pageInfo(pages));
    }

    @ApiOperation(value = "其他课程")
    @PostMapping("/otherLesson")
    public HttpResponseResult<List<VideoLessonGroupVo>> otherLesson(@RequestBody VideoLessonGroupSearch query) {

    	query.setAuditStatus(AuthStatusEnum.PASS.getCode());
    	query.setShelvesFlag(1);
        // 检查app版本
        query.setAuditVersion(appVersionInfoService.getAppAuditVersion(query.getPlatform(),query.getVersion()));
        return succeed(videoLessonGroupService.selectPage(query));
    }
}
