package com.yonge.cooleshow.website.controller;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.dto.req.TeacherApplyDetailReq;
import com.yonge.cooleshow.biz.dal.service.TeacherAuthEntryRecordService;
import com.yonge.cooleshow.biz.dal.vo.TeacherAuthEntryRecordVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.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.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/teacherAuthEntryRecord")
@Api(value = "老师入驻审核表", tags = "老师入驻审核表")
public class TeacherAuthEntryRecordController extends BaseController {
    @Autowired
    private TeacherAuthEntryRecordService teacherAuthEntryRecordService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @GetMapping("/getLastRecordByUserId")
    @ApiOperation(value = "获取最近一次提交的申请内容")
    public HttpResponseResult<TeacherAuthEntryRecordVo> getLastRecordByUserId() {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        TeacherAuthEntryRecordVo detail = teacherAuthEntryRecordService.getLastRecordByUserId(user.getId());
        return succeed(detail);
    }

    @PostMapping("/doApply")
    @ApiOperation(value = "提交申请", notes = "传入teacherAuthEntryRecord")
    public HttpResponseResult<Boolean> doApply(@Valid @RequestBody TeacherApplyDetailReq teacherApplyDetailDto) throws Exception {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        //处理老师申请逻辑
        return teacherAuthEntryRecordService.doApply(teacherApplyDetailDto, user);
    }
}