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.enums.YesOrNoEnum;
import com.yonge.cooleshow.biz.dal.service.CourseHomeworkService;
import com.yonge.cooleshow.biz.dal.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.mybatis.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.web.bind.annotation.*;

import javax.validation.Valid;

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

    @Autowired
    private CourseHomeworkService courseHomeworkService;


	@ApiOperation(value = "课后作业-列表", httpMethod = "POST", consumes = "application/json", produces = "application/json")
	@PostMapping(value = "/list", consumes = "application/json", produces = "application/json")
	public HttpResponseResult<PageInfo<CourseHomeworkVo>> list(@Valid @RequestBody HomeworkAdminSearch query) {
		query.setDecorate(YesOrNoEnum.YES);
		query.setCourseStatus(CourseScheduleEnum.COMPLETE);
		query.setCourseType(CourseScheduleEnum.PRACTICE);
		return succeed(PageUtil.pageInfo(courseHomeworkService.selectAdminPage(PageUtil.getPage(query),query)));
	}


	@ApiOperation(value = "首页-我的课程-课程详情(陪练课)-课后作业信息详情",notes = "传入课程编号ID")
	@GetMapping(value = "/detail/{courseId}")
	public HttpResponseResult<CourseHomeworkDetailVo> detail(@ApiParam(value = "课程编号ID", required = true)
															 @PathVariable("courseId") Long courseId) {
		return succeed(courseHomeworkService.getCourseHomeworkDetailByCourseId(courseId));
	}
}