package com.ym.mec.teacher.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.ExtracurricularExercises;
import com.ym.mec.biz.dal.page.ExtraExercilseQueryInfo;
import com.ym.mec.biz.service.ExtracurricularExercisesReplyService;
import com.ym.mec.biz.service.ExtracurricularExercisesService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 java.util.Objects;

/**
 * @Author Joburgess
 * @Date 2020/3/26
 */
@Api(tags = "课外训练服务")
@RequestMapping("extracurricularExercises")
@RestController
public class ExtracurricularExercisesController extends BaseController {

    @Autowired
    private ExtracurricularExercisesService extracurricularExercisesService;
    @Autowired
    private ExtracurricularExercisesReplyService extracurricularExercisesReplyService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "创建课外训练")
    @PostMapping("/createExtraExercises")
    private HttpResponseResult createExtraExercises(ExtracurricularExercises exercises){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(sysUser)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        exercises.setTeacherId(sysUser.getId());
        extracurricularExercisesService.createExtraExercises(exercises);
        return succeed();
    }

    @ApiOperation(value = "获取课外训练列表")
    @GetMapping("/findExtraExercilses")
    private HttpResponseResult findExtraExercilses(ExtraExercilseQueryInfo queryInfo){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(sysUser)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        queryInfo.setTeacherId(sysUser.getId());
        return succeed(extracurricularExercisesService.findExtraExercilses(queryInfo));
    }

    @ApiOperation(value = "获取课外训练详情")
    @GetMapping("/findStudentExtraExerciseDetail")
    private HttpResponseResult findStudentExtraExerciseDetail(Long studentExerciseId){
        if(Objects.isNull(studentExerciseId)){
            return failed("请选择课外训练作业");
        }
        return succeed(extracurricularExercisesReplyService.findStudentExtraExerciseDetail(studentExerciseId));
    }

    @ApiOperation(value = "获取待布置学员列表")
    @GetMapping("/getDontServeStudents")
    public HttpResponseResult getDontServeStudents(String search){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(sysUser)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        return succeed(extracurricularExercisesService.getDontServeStudents(sysUser.getId(), search));
    }
}
