package com.yonge.cooleshow.admin.controller;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.biz.dal.dto.search.CourseGroupDetailSearch;
import com.yonge.cooleshow.biz.dal.dto.search.CourseGroupSearch;
import com.yonge.cooleshow.biz.dal.entity.VideoLessonGroupDetail;
import com.yonge.cooleshow.biz.dal.service.CourseGroupService;
import com.yonge.cooleshow.biz.dal.service.CourseScheduleService;
import com.yonge.toolset.mybatis.support.PageUtil;
import com.yonge.cooleshow.biz.dal.vo.*;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.base.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @Author: cy
 * @Date: 2022/5/19
 */
@RestController
@RequestMapping("/courseGroup")
@Api(tags = "课程组")
@Validated
public class CourseGroupController extends BaseController {
    @Autowired
    private CourseGroupService courseGroupService;
    @Autowired
    private CourseScheduleService courseScheduleService;

    @ApiOperation(value = "课程组管理-陪练课", notes = "{\n" +
            "    \"subjectId\":20,\n" +
            "    \"search\":\"师\",\n" +
            "    \"status\":\"ING\"\n" +
            "}")
    @PostMapping(value = "/practice")
    public HttpResponseResult<PageInfo<CourseGroupPracticeVo>> selectPracticeGroup(@RequestBody CourseGroupSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectPracticeGroup(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "课程组管理-陪练课-详情", notes = "{\n" +
            "    \"courseGroupId\": 140,\n" +
            "    \"teacherSign\": 0,\n" +
            "    \"studentSign\": 0,\n" +
            "    \"search\": \"游\",\n" +
            "    \"status\": \"COMPLETE\",\n" +
            "    \"salaryStatus\": \"NOT_START\",\n" +
            "    \"startTime\": \"2022-05-21 08:00:00\",\n" +
            "    \"endTime\": \"\"\n" +
            "}")
    @PostMapping(value = "/practice/detail")
    public HttpResponseResult<PageInfo<CourseGroupPracticeDetailVo>> selectPracticeGroupDetail(@Validated @RequestBody CourseGroupDetailSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectPracticeGroupDetail(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "课程组管理-直播课", notes = "{\n" +
            "    \"subjectId\":73,\n" +
            "    \"search\":\"夏\",\n" +
            "    \"status\":\"ING\"\n" +
            "}")
    @PostMapping(value = "/live")
    public HttpResponseResult<PageInfo<CourseGroupLiveVo>> selectLiveGroup(@RequestBody CourseGroupSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectLiveGroup(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "课程组管理-直播课-购买学员", notes = "{\n" +
            "    \"groupId\":140,\n" +
            "    \"search\":\"游\",\n" +
            "    \"orderNo\":\"22051615250800001\"\n" +
            "}")
    @PostMapping(value = "/live/studentPayment")
    public HttpResponseResult<PageInfo<CourseSchedulePaymentVo>> selectLiveGroupStudent(@RequestBody CourseGroupSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectLiveGroupStudent(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "课程组管理-直播课-教学计划", notes = "{\n" +
            "    \"groupId\":140,\n" +
            "    \"courseId\":\"391\",\n" +
            "    \"salaryStatus\":\"NOT_START\",\n" +
            "    \"startTime\":\"2022-05-20 08:00:00\",\n" +
            "    \"endTime\":null\n" +
            "}")
    @PostMapping(value = "/live/plan")
    public HttpResponseResult<PageInfo<CourseSchedulePlanVo>> selectLiveGroupPlan(@RequestBody CourseGroupSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectLiveGroupPlan(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "课程组管理-视频课", notes = "{\n" +
            "    \"subjectId\":21,\n" +
            "    \"search\":\"老\"\n" +
            "}")
    @PostMapping(value = "/video")
    public HttpResponseResult<PageInfo<CourseGroupVideoVo>> selectVideoGroup(@RequestBody CourseGroupSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectVideoGroup(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "课程组管理-视频课-购买学员", notes = "{\n" +
            "    \"groupId\":51,\n" +
            "    \"orderNo\":\"22050720002900001\",\n" +
            "    \"search\":\"1\",\n" +
            "    \"startTime\":\"2022-05-07 20:00:29\",\n" +
            "    \"endTime\":null\n" +
            "}")
    @PostMapping(value = "/video/studentPayment")
    public HttpResponseResult<PageInfo<CourseGroupStudentVo>> selectVideoGroupStudent(@RequestBody CourseGroupSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectVideoGroupStudent(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "课程组管理-视频课-教学计划", notes = "{\n" +
            "    \"groupId\":18\n" +
            "}")
    @PostMapping(value = "/video/plan")
    public HttpResponseResult<PageInfo<VideoLessonGroupDetail>> selectVideoGroupPlan(@RequestBody CourseGroupSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectVideoGroupPlan(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "课程组管理-直播课-课程信息")
    @GetMapping(value = "/live/info")
    public HttpResponseResult<CourseGroupInfoVo> selectLiveGroupInfo(@NotNull Long groupId) {
        return succeed(courseGroupService.selectLiveGroupInfo(groupId));
    }

    @ApiOperation(value = "课程组管理-琴房课", notes = "{\n" +
            "    \"subjectId\":20,\n" +
            "    \"search\":\"师\",\n" +
            "    \"status\":\"ING\"\n" +
            "}")
    @PostMapping(value = "/piano")
    public HttpResponseResult<PageInfo<CourseGroupPianoVo>> selectPianoGroup(@RequestBody CourseGroupSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectPianoGroup(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "课程组管理-琴房课-详情", notes = "{\n" +
            "    \"courseGroupId\":334,\n" +
            "    \"search\":\"\",\n" +
            "    \"status\":\"\",\n" +
            "    \"startTime\":null,\n" +
            "    \"endTime\":null,\n" +
            "    \"teacherSign\":null,\n" +
            "    \"studentSign\":null\n" +
            "}")
    @PostMapping(value = "/piano/detail")
    public HttpResponseResult<PageInfo<CourseGroupPianoDetailVo>> selectPianoGroupDetail(@Validated @RequestBody CourseGroupDetailSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectPianoGroupDetail(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "课程组管理-琴房课-详情-学员名单")
    @GetMapping(value = "/piano/student")
    public HttpResponseResult<List<StudentSignVo>> studentSign(@NotNull Long courseId) {
        return succeed(courseGroupService.studentSign(courseId, null));
    }

    @ApiOperation(value = "学员管理-琴房课", notes = "{\n" +
            "    \"studentId\":20,\n" +
            "    \"search\":\"师\",\n" +
            "    \"status\":\"ING\"\n" +
            "}")
    @PostMapping(value = "/piano/student")
    public HttpResponseResult<PageInfo<CourseGroupPianoVo>> selectPianoGroupStudent(@RequestBody CourseGroupSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectPianoGroupStudent(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "学员管理-琴房课-详情", notes = "{\n" +
            "    \"studentId\":20,\n" +
            "    \"courseGroupId\":334,\n" +
            "    \"search\":\"\",\n" +
            "    \"status\":\"\",\n" +
            "    \"startTime\":null,\n" +
            "    \"endTime\":null,\n" +
            "    \"teacherSign\":0,\n" +
            "    \"studentSign\":0\n" +
            "}")
    @PostMapping(value = "/piano/student/detail")
    public HttpResponseResult<PageInfo<CourseGroupPianoDetailVo>> selectPianoGroupStudentDetail(@Validated @RequestBody CourseGroupDetailSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectPianoGroupStudentDetail(PageUtil.getPage(search), search)));
    }

    @ApiOperation("查询琴房剩余时长、冻结时长、统计学员人数")
    @GetMapping("/selectRemainTime")
    public HttpResponseResult<PianoRoomTimeVo> selectRemainTime(Long teacherId) {
        return succeed(courseScheduleService.selectRemainTime(teacherId));
    }

    @ApiOperation(value = "老师管理-琴房课", notes = "{\n" +
            "    \"teacherId\":20,\n" +
            "    \"search\":\"师\",\n" +
            "    \"status\":\"ING\"\n" +
            "}")
    @PostMapping(value = "/piano/teacher")
    public HttpResponseResult<PageInfo<CourseGroupPianoVo>> selectPianoGroupTeacher(@RequestBody CourseGroupSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectPianoGroupTeacher(PageUtil.getPage(search), search)));
    }

    @ApiOperation(value = "老师管理-琴房课-详情", notes = "{\n" +
            "    \"teacherId\":20,\n" +
            "    \"courseGroupId\":334,\n" +
            "    \"search\":\"\",\n" +
            "    \"status\":\"\",\n" +
            "    \"startTime\":null,\n" +
            "    \"endTime\":null,\n" +
            "    \"teacherSign\":0,\n" +
            "    \"studentSign\":0\n" +
            "}")
    @PostMapping(value = "/piano/teacher/detail")
    public HttpResponseResult<PageInfo<CourseGroupPianoDetailVo>> selectPianoGroupTeacherDetail(@Validated @RequestBody CourseGroupDetailSearch search) {
        return succeed(PageUtil.pageInfo(courseGroupService.selectPianoGroupTeacherDetail(PageUtil.getPage(search), search)));
    }
}