package com.ym.mec.student.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.CourseScheduleComplaints;
import com.ym.mec.biz.dal.enums.GroupType;
import com.ym.mec.biz.dal.page.StudentCourseScheduleRecordQueryInfo;
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.web.bind.annotation.*;

import java.util.Date;

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

	@Autowired
	private CourseScheduleService scheduleService;

	@Autowired
	private StudentAttendanceService studentAttendanceService;

	@Autowired
	private SysUserFeignService sysUserFeignService;

	@ApiOperation(value = "根据月份获取乐团在该月有课的日期")
	@GetMapping("/getCourseScheduleDateByMonth")
	public Object getCourseScheduleDateByMonth(@ApiParam(value = "月份", required = true) @RequestParam Date month,
			@ApiParam(value = "未上课", required = true) Integer isAttend) {
		return succeed(scheduleService.getCourseScheduleDateByStudent(month, isAttend));
	}

	@ApiOperation(value = "根据日期获取当日排课")
	@GetMapping("/getCourseSchedulesWithDate")
	public Object getCourseSchedulesWithDate(@ApiParam(value = "日期", required = true) Date date) {
		return succeed(scheduleService.getStudentCourseSchedulesWithDate(date));
	}

	@ApiOperation(value = "上课记录")
	@GetMapping(value = "/findStudentCourseScheduleRecords")
	public Object findStudentCourseScheduleRecords(StudentCourseScheduleRecordQueryInfo queryInfo) {
		return succeed(scheduleService.findStudentCourseScheduleRecords(queryInfo));
	}

	@ApiOperation(value = "课程投诉")
	@PostMapping("/courseScheduleCommplaint")
	public Object courseScheduleCommplaint(CourseScheduleComplaints courseScheduleComplaints) {
		scheduleService.courseScheduleCommplaint(courseScheduleComplaints);
		return succeed();
	}

	@ApiOperation(value = "请假")
	@PostMapping("/leave")
	public Object leave(Long courseScheduleId, String reason) {
		SysUser user = sysUserFeignService.queryUserInfo();
		if (user == null) {
			return failed(HttpStatus.FORBIDDEN, "请登录");
		}
		studentAttendanceService.leave(user.getId(), courseScheduleId, reason);
		return succeed();
	}

	@ApiOperation(value = "根据课程组获取课程组老师信息")
	@GetMapping("/teacherCourseHeadInfo")
	public Object teacherCourseHeadInfo(GroupType groupType,String groupId,Long courseScheduleId){
		return succeed(scheduleService.getTeacherCourseHeadInfo(groupType,groupId,courseScheduleId));
	}

	@ApiOperation(value = "根据课程组获取课表信息")
	@GetMapping("/queryCourseInfoByGroupId")
	public Object queryCourseInfoByGroupId(GroupType groupType,String groupId){
		return succeed(scheduleService.queryCourseInfoByGroupId(groupType,groupId));
	}

}
