package com.cool.store.controller.webb;

import com.cool.store.context.CurrentUserHolder;
import com.cool.store.enums.InterviewUserTypeEnum;
import com.cool.store.exception.ApiException;
import com.cool.store.request.AppointmentTimeRequest;
import com.cool.store.request.InterviewUploadVideoRequest;
import com.cool.store.request.LineInterviewPageRequest;
import com.cool.store.request.ModifyInterviewerRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.LineInterviewService;
import com.cool.store.vo.interview.*;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * @author zhangchenbiao
 * @FileName: LineInterviewController
 * @Description:
 * @date 2024-03-15 16:04
 */
@RestController
@RequestMapping("/pc/interview/")
@Api(tags = "PC端-面试&面谈")
@Slf4j
public class PCLineInterviewController {

    @Resource
    private LineInterviewService lineInterviewService;

    @ApiOperation("获取面试/面谈 预约时间")
    @GetMapping("/appointment/time")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "lineId", value = "线索id", required = true),
            @ApiImplicitParam(name = "interviewType", value = "面试类型:0面谈;1面试", required = true),
            @ApiImplicitParam(name = "appointmentDate", value = "预约日期 yyyy-MM-dd", required = true)
    })
    public ResponseResult<List<AppointmentTimeListVO>> getAppointmentTime(@RequestParam("lineId")Long lineId,
                                                                          @RequestParam("interviewType")Integer interviewType,
                                                                          @RequestParam("appointmentStartDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate appointmentStartDate,
                                                                          @RequestParam("appointmentEndDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate appointmentEndDate) {
        return ResponseResult.success(lineInterviewService.getAppointmentTime(lineId, interviewType, appointmentStartDate, appointmentEndDate));
    }

    @ApiOperation("修改面审时间")
    @PostMapping("/appointment/time/modify")
    public ResponseResult<Boolean> modifyAppointmentTime(@RequestBody @Validated AppointmentTimeRequest request) {
        return ResponseResult.success(lineInterviewService.modifyAppointmentTime(request));
    }

    @ApiOperation("修改面试官")
    @PostMapping("/modify")
    public ResponseResult<Boolean> modifyInterviewer(@RequestBody @Validated ModifyInterviewerRequest request) {
        request.setOperatorUserId(CurrentUserHolder.getUserId());
        return ResponseResult.success(lineInterviewService.modifyInterviewer(request));
    }

    @ApiOperation("一审列表/二审列表")
    @PostMapping("/page")
    public ResponseResult<PageInfo<LineInterviewPageVO>> getInterviewerPage(@RequestBody LineInterviewPageRequest request) {
        request.setInterviewerUserId(CurrentUserHolder.getUserId());
        return ResponseResult.success(lineInterviewService.getInterviewerPage(request, CurrentUserHolder.getUserId(), Boolean.FALSE));
    }

    @ApiOperation("团队一审/团队二审")
    @PostMapping("/team/page")
    public ResponseResult<PageInfo<LineInterviewPageVO>> getTeamInterviewerPage(@RequestBody LineInterviewPageRequest request) {
        return ResponseResult.success(lineInterviewService.getInterviewerPage(request, CurrentUserHolder.getUserId(), Boolean.TRUE));
    }

    @ApiOperation("获取面试信息")
    @GetMapping("/detail")
    public ResponseResult<InterviewDetailVO> getInterviewDetail(@RequestParam("lineId")Long lineId, @RequestParam("interviewType")Integer interviewType) {
        return ResponseResult.success(lineInterviewService.getInterviewDetail(lineId, interviewType));
    }

    @ApiOperation("进入房间")
    @GetMapping("/room/enter")
    public ResponseResult<EnterInterviewVO> enterInterviewRoom(@RequestParam("interviewId")Long interviewId) {
        String userId = CurrentUserHolder.getUserId();
        return ResponseResult.success(lineInterviewService.enterInterviewRoom(interviewId, userId, InterviewUserTypeEnum.INTERVIEWER));
    }

    @ApiOperation("结束面试")
    @GetMapping("/finish")
    public ResponseResult finishInterview(@RequestParam("interviewId")Long interviewId) {
        String userId = CurrentUserHolder.getUserId();
        lineInterviewService.finishInterview(interviewId, userId);
        return ResponseResult.success();
    }

    @ApiOperation("上传文件")
    @PostMapping("/upload/video")
    public ResponseResult uploadVideo(@RequestBody @Validated InterviewUploadVideoRequest request) {
        return ResponseResult.success(lineInterviewService.uploadVideo(request.getInterviewId(), request.getVideoUrlList()));
    }

    @ApiOperation("重新面审")
    @GetMapping("/reappointment")
    public ResponseResult reappointment(@RequestParam("lineId")Long lineId) {
        return ResponseResult.success(lineInterviewService.reappointment(lineId));
    }
}
