package com.yonge.cooleshow.teacher.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.dto.search.MyCourseSearch;
import com.yonge.cooleshow.biz.dal.entity.CourseCalendarEntity;
import com.yonge.cooleshow.biz.dal.service.CourseScheduleService;
import com.yonge.cooleshow.biz.dal.support.PageUtil;
import com.yonge.cooleshow.biz.dal.vo.CourseAdjustVo;
import com.yonge.cooleshow.biz.dal.vo.MyCourseVo;
import com.yonge.cooleshow.biz.dal.vo.TeacherLiveCourseInfoVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.mybatis.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 老师课程表(CourseSchedule)表控制层
 *
 * @author hgw
 * @since 2022-03-18 15:29:11
 */
@Api(tags = "老师课程表")
@RestController
@RequestMapping("/courseSchedule")
public class TeacherCourseScheduleController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private CourseScheduleService courseScheduleService;
    @Resource
    private SysUserFeignService sysUserFeignService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "classDate", dataType = "Integer", value = "年月"),
            @ApiImplicitParam(name = "status", dataType = "String", value = "课程状态 NOT_START未开始 ING进行中 COMPLETE已完成"),
            @ApiImplicitParam(name = "subjectId", dataType = "Long", value = "声部id"),
            @ApiImplicitParam(name = "page", dataType = "Integer", value = "页数"),
            @ApiImplicitParam(name = "rows", dataType = "Integer", value = "每页数量"),
    })
    @ApiOperation("老师端-首页-我的课程-直播课")
    @PostMapping("/queryTeacherLiveCourse")
    public HttpResponseResult<PageInfo<TeacherLiveCourseInfoVo>> queryTeacherLiveCourse(@RequestBody Map<String, Object> param) {
        return succeed(courseScheduleService.queryTeacherLiveCourse(param));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "year", dataType = "Integer", value = "年"),
            @ApiImplicitParam(name = "month", dataType = "Integer", value = "月"),
            @ApiImplicitParam(name = "singleCourseMinutes", dataType = "Integer", value = "单课时时长(不包含休息时间)"),
            @ApiImplicitParam(name = "freeCourseMinutes", dataType = "Integer", value = "单课时休息时长)"),
            @ApiImplicitParam(name = "teacherId", dataType = "Long", value = "老师id"),
    })
    @ApiOperation("直播课创建时的日历数据")
    @PostMapping("/createLiveCourseCalendar")
    public HttpResponseResult<List<CourseCalendarEntity>> createLiveCourseCalendar(@RequestBody Map<String, Object> param) {
        return succeed(courseScheduleService.createLiveCourseCalendar(param));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "teacherId", dataType = "Long", value = "老师id"),
            @ApiImplicitParam(name = "studentId", dataType = "Long", value = "学生id"),
            @ApiImplicitParam(name = "year", dataType = "Integer", value = "年"),
            @ApiImplicitParam(name = "month", dataType = "Integer", value = "月"),
            @ApiImplicitParam(name = "day", dataType = "Integer", value = "日"),
    })
    @ApiOperation("陪练课日历-用于学生购买指定老师陪练课")
    @PostMapping("/createPracticeCourseCalendar")
    public HttpResponseResult<List<CourseCalendarEntity>> generatePracticeCourseCalender(@RequestBody Map<String, Object> param) {
        return succeed(courseScheduleService.createPracticeCourseCalender(param));
    }

    @ApiOperation(value = "陪练课查询",
            notes = "老师端-首页-我的课程-陪练课\n" +
            "search:{\"classMonth\":\"2022-03\",\"status\":\"COMPLETE\",\"subjectId\":1}\n" +
            "老师端-首页-课后评价\n" +
            "search:{\"classMonth\":\"2022-03\",\"replied\":0,\"studentName\":\"测试王\"}\n" +
            "老师端-我的-我的主页\n" +
            "search:{\"classMonth\":\"2022-03\"}\n" +
            "老师端-课表\n" +
            "search:{\"classDate\":\"2022-03-27\"}\n" +
            "     search:{\"classMonth\":\"2022-03\"}\n" +
            "老师端-课表-陪练课\n" +
            "     search:{\"classDate\":\"2022-03-27\"}")
    @PostMapping("/queryTeacherPracticeCourse")
    public HttpResponseResult<PageInfo<MyCourseVo>> queryTeacherPracticeCourse(@RequestBody MyCourseSearch search) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        search.setTeacherId(user.getId());
        IPage<MyCourseVo> pages = courseScheduleService.queryTeacherPracticeCourse(PageUtil.getPage(search), search);
        return succeed(PageUtil.pageInfo(pages));
    }

    @ApiOperation("老师端-课表-日历")
    @PostMapping("/queryCourseSchedule")
    public HttpResponseResult<Set<String>> queryCourseSchedule(@RequestBody MyCourseSearch search) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        search.setTeacherId(user.getId());
        return succeed(courseScheduleService.queryCourseSchedule(search));
    }

    @ApiOperation(value = "老师端-课表-日历-用户",notes = "search:{\"classDate\":\"2022-03-27\"}")
    @PostMapping("/queryCourseUser")
    public HttpResponseResult<Map<String,Object>> queryCourseUser(@RequestBody MyCourseSearch search) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        search.setTeacherId(user.getId());
        return succeed(courseScheduleService.queryCourseUser(search));
    }

    @ApiOperation(value = "老师端-课表-日历-调课")
    @PostMapping("/courseAdjust")
    public HttpResponseResult<Object> courseAdjust(@Validated @RequestBody CourseAdjustVo adjustVo) {
        courseScheduleService.courseAdjust(adjustVo);
        return succeed();
    }
}

