package com.ym.mec.education.controller;

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

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dto.ClassDateAdjustDto;
import com.ym.mec.biz.dal.entity.CourseSchedule;
import com.ym.mec.biz.service.CourseScheduleService;
import com.ym.mec.common.exception.BizException;
import com.ym.mec.education.base.BaseResponse;
import com.ym.mec.education.base.PageResponse;
import com.ym.mec.education.req.ClassGroupReq;
import com.ym.mec.education.req.CourseScheduleReq;
import com.ym.mec.education.resp.CourseScheduleResp;
import com.ym.mec.education.service.ICourseScheduleService;

/**
 * @program: mec
 * @description: 课表
 * @author: xw
 * @create: 2019-09-26 21:04
 */
@RestController
@RequestMapping("api/courseSchedule")
@Api(tags = "课表")
@Slf4j
public class CourseScheduleController {

    @Autowired
    private ICourseScheduleService courseScheduleService;
    @Autowired
    private CourseScheduleService scheduleService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @PostMapping("/list")
    @ApiOperation("课表列表")
    public PageResponse list(@RequestBody @Validated ClassGroupReq classGroupReq) {
        return courseScheduleService.getPage(classGroupReq);
    }

    @PostMapping("/info")
    @ApiOperation("点名详情-头信息")
    public BaseResponse<CourseScheduleResp> getInfo(@RequestBody CourseScheduleReq courseScheduleReq) {
        return courseScheduleService.getInfo(courseScheduleReq);
    }

    @PostMapping("/statisticsInfo")
    @ApiOperation("历史考勤统计-头信息")
    public BaseResponse getStatisticsInfo(@RequestBody ClassGroupReq classGroupReq) {
        return courseScheduleService.getStatisticsInfo(classGroupReq);
    }


    @PostMapping("/courseInfo")
    @ApiOperation("课程详情-头信息")
    public BaseResponse<CourseScheduleResp> courseInfo(@RequestBody CourseScheduleReq courseScheduleReq) {
        return courseScheduleService.courseInfo(courseScheduleReq);
    }

    @ApiOperation(value = "课时调整")
    @PostMapping(value = "/classStartDateAdjust")
    public Object classStartDateAdjust(ClassDateAdjustDto classDateAdjustDto){
        if(Objects.isNull(classDateAdjustDto.getId())){
            return BaseResponse.errorParam();
        }
        List<CourseSchedule> courseSchedules=new ArrayList<>();
        courseSchedules.add(classDateAdjustDto);
        scheduleService.courseAdjust(courseSchedules);
        return BaseResponse.success(null);
    }

    @ApiOperation(value = "课时交换")
    @GetMapping(value = "/courseSwap")
    public Object courseSwap(Long courseScheduleId1,Long courseScheduleId2){
        if(Objects.isNull(courseScheduleId1)||Objects.isNull(courseScheduleId2)){
            return BaseResponse.errorParam();
        }
        scheduleService.courseSwap(courseScheduleId1,courseScheduleId2);
        return BaseResponse.success(null);
    }

}
