package com.ym.mec.teacher.controller;

import com.ym.mec.biz.dal.dto.ClassDateAdjustDto;
import com.ym.mec.biz.dal.dto.CourseScheduleDto;
import com.ym.mec.biz.dal.enums.StudentAttendanceStatusEnum;
import com.ym.mec.biz.dal.page.StudentAttendanceQueryInfo;
import com.ym.mec.biz.service.CourseScheduleService;
import com.ym.mec.biz.service.StudentAttendanceService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @Author Joburgess
 * @Date 2019/9/27
 */
@Api(tags = "课程计划服务")
@RequestMapping("teacherCourseSchedule")
@RestController
public class TeacherCourseScheduleController extends BaseController {

    @Autowired
    private CourseScheduleService scheduleService;
    @Autowired
    private StudentAttendanceService studentAttendanceService;

    @ApiOperation(value = "根据月份获取该月有课的日期")
    @GetMapping("/getCourseScheduleDateByMonth")
    public Object getCourseScheduleDateByMonth(@ApiParam(value = "月份", required = true) @RequestParam Date month) {
        if(Objects.isNull(month)){
            return failed(HttpStatus.FORBIDDEN, "请指定日期!");
        }
        return succeed(scheduleService.getCourseScheduleDateByTeacher(month));
    }

    @ApiOperation(value = "根据日期获取当日排课")
    @GetMapping("/getCourseSchedulesWithDate")
    public Object getCourseSchedulesWithDate(@ApiParam(value = "日期", required = true) Date date){
        if(Objects.isNull(date)){
            return failed(HttpStatus.FORBIDDEN, "请指定日期!");
        }
        List<CourseScheduleDto> teacherCourseSchedulesWithDate = scheduleService.getTeacherCourseSchedulesWithDate(date);
        Map<String,Object> result = new HashMap<>();
        result.put("rows",teacherCourseSchedulesWithDate);
        result.put("appealDaysRange",1);
        return succeed(result);
    }

    @ApiOperation(value = "根据课程ID查询打卡界面课程详情")
    @GetMapping("/getCurrentCourseDetail")
    public Object getCurrentCourseDetail(Long courseID){
        if(Objects.isNull(courseID)){
            return failed(HttpStatus.FORBIDDEN, "请指定课程!");
        }
        return succeed(scheduleService.getCurrentCourseDetail(courseID));
    }

    @ApiOperation(value = "根据班级ID获取当前课程的学生列表")
    @GetMapping("/getCurrentCourseStudents")
    public Object getCurrentCourseStudents(StudentAttendanceQueryInfo queryInfo){
        if(Objects.isNull(queryInfo.getClassGroupId())){
            return failed(HttpStatus.FORBIDDEN, "请指定班级!");
        }
        queryInfo.setFilterStatus(StudentAttendanceStatusEnum.DROP_OUT);
        return succeed(studentAttendanceService.getCurrentCourseStudents(queryInfo));
    }

    @ApiOperation(value = "课时调整")
    @PostMapping(value = "/classStartDateAdjust",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object classStartDateAdjust(ClassDateAdjustDto classDateAdjustDto){
        if(Objects.isNull(classDateAdjustDto.getId())){
            return failed(HttpStatus.FORBIDDEN, "请指定课程!");
        }
        scheduleService.classStartDateAdjust(classDateAdjustDto);
        return succeed();
    }

    @ApiOperation(value = "课时交换")
    @GetMapping(value = "/courseSwap",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object courseSwap(Long courseScheduleId1,Long courseScheduleId2){
        if(Objects.isNull(courseScheduleId1)||Objects.isNull(courseScheduleId2)){
            return failed(HttpStatus.FORBIDDEN, "请指定课程!");
        }
        scheduleService.courseSwap(courseScheduleId1,courseScheduleId2);
        return succeed();
    }

}
