package com.yonge.cooleshow.admin.controller;

import com.yonge.cooleshow.biz.dal.dto.search.HomeworkAdminSearch;
import com.yonge.cooleshow.biz.dal.enums.CourseScheduleEnum;
import com.yonge.cooleshow.biz.dal.service.CourseHomeworkService;
import com.yonge.cooleshow.biz.dal.service.CourseScheduleService;
import com.yonge.cooleshow.common.enums.YesOrNoEnum;
import com.yonge.toolset.mybatis.support.PageUtil;
import com.yonge.cooleshow.biz.dal.vo.CourseHomeworkDetailVo;
import com.yonge.cooleshow.biz.dal.vo.CourseHomeworkVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.base.page.PageInfo;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/homework")
@Api(value = "课程作业表", tags = "课程作业表")
public class CourseHomeworkController extends BaseController {

    @Autowired
    private CourseHomeworkService courseHomeworkService;

	@Autowired
	private CourseScheduleService courseScheduleService;

	@ApiOperation(value = "课后作业-列表", httpMethod = "POST", consumes = "application/json", produces = "application/json")
	@PostMapping(value = "/list", consumes = "application/json", produces = "application/json")
	@PreAuthorize("@pcs.hasPermissions('homework/list')")
	public HttpResponseResult<PageInfo<CourseHomeworkVo>> list(@Valid @RequestBody HomeworkAdminSearch query) {
		query.setDecorate(YesOrNoEnum.YES);
		query.setCourseStatus(CourseScheduleEnum.COMPLETE);

		List<CourseScheduleEnum> list = new ArrayList<>();
		list.add(CourseScheduleEnum.PIANO_ROOM_CLASS);
		list.add(CourseScheduleEnum.PRACTICE);
		query.setCourseType(list);
		return succeed(PageUtil.pageInfo(courseHomeworkService.selectAdminPage(PageUtil.getPage(query),query)));
	}


	@ApiOperation(value = "课后作业-详情",notes = "传入课程编号ID")
	@GetMapping(value = "/detail/{courseId}/{studentId}")
	@PreAuthorize("@pcs.hasPermissions('homework/detail')")
	public HttpResponseResult<CourseHomeworkDetailVo> detail(@ApiParam(value = "课程编号ID", required = true)
															 @PathVariable("courseId") Long courseId,
															 @PathVariable("studentId") Long studentId) {
		return succeed(courseHomeworkService.getCourseHomeworkDetailByCourseId(courseId,studentId));
	}



	@PostMapping(value = "/teacherSend")
	@ApiOperation(value = "发送老师未评价和未布置作业消息")
	@PreAuthorize("@pcs.hasPermissions('homework/teacherSend')")
	public HttpResponseResult<Object> sendTodayNotRepliedAndNotDecorateHomework() {
		courseScheduleService.sendTodayNotRepliedAndNotDecorateHomework();
		return HttpResponseResult.succeed();
	}
}