package com.ym.mec.teacher.controller;

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

import java.util.Date;
import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
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.dao.CourseScheduleDao;
import com.ym.mec.biz.dal.entity.TeacherLeaveRecord;
import com.ym.mec.biz.service.TeacherLeaveRecordService;
import com.ym.mec.common.controller.BaseController;

@Api(tags = "老师请假服务")
@RequestMapping("teacherLeaveRecord")
@RestController
public class TeacherLeaveRecordController extends BaseController {

	@Autowired
	private SysUserFeignService sysUserFeignService;

	@Autowired
	private CourseScheduleDao courseScheduleDao;

	@Autowired
	private TeacherLeaveRecordService teacherLeaveRecordService;

	@ApiOperation(value = "查询vip课列表")
	@GetMapping("/queryVipCourseScheduleList")
	public Object queryVipCourseScheduleList(Date startTime, Date endTime) {
		SysUser sysUser = sysUserFeignService.queryUserInfo();
		if (Objects.isNull(sysUser)) {
			return failed(HttpStatus.FORBIDDEN, "请登录");
		}
		return succeed(courseScheduleDao.queryTeacherCourseScheduleListByTimeRangeAndType(sysUser.getId(), null, startTime, endTime));
	}

	@ApiOperation(value = "请假")
	@PostMapping("/askForLeave")
	public Object askForLeave(TeacherLeaveRecord teacherLeaveRecord) {
		teacherLeaveRecordService.askForLeave(teacherLeaveRecord);
		return succeed();
	}
}
