package com.sqx.modules.interviewRecord.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.app.service.UserService;
import com.sqx.modules.interviewRecord.entity.HrPhone;
import com.sqx.modules.interviewRecord.entity.InterviewRecord;
import com.sqx.modules.interviewRecord.service.HrPhoneService;
import com.sqx.modules.interviewRecord.service.InterviewRecordService;
import com.sqx.modules.resumes.entity.Company;
import com.sqx.modules.resumes.service.CompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 面试邀约记录
 * </p>
 *
 * @author wuchang
 * @since 2023-02-08
 */
@RestController
@RequestMapping("/app/interviewRecord/")
public class InterviewRecordController {
    @Autowired
    private InterviewRecordService recordService;
    @Autowired
    private UserService userService;
    @Autowired
    private CompanyService companyService;
    @Autowired
    private InterviewRecordService interviewRecordService;
    @Autowired
    private HrPhoneService hrPhoneService;

    @Login
    @ApiOperation("获取面试记录列表")
    @GetMapping("interviewList")
    public Result interviewList(@RequestAttribute("userId")Long userId, Integer page, Integer limit, InterviewRecord interviewRecord) {
            interviewRecord.setInterviewerId(Math.toIntExact(userId));
        return Result.success().put("data", recordService.interviewList(page, limit, interviewRecord));
    }
    @Login
    @GetMapping("getHrInterviewList")
    @ApiOperation("招聘端获取自己发布的岗位")
    public Result getHrInterviewList(@RequestAttribute("userId")Long userId, Integer page, Integer limit, InterviewRecord interviewRecord) {
        interviewRecord.setUserId(userId);
        return Result.success().put("data", recordService.interviewList(page, limit, interviewRecord));
    }

    @ApiOperation("获取面试记录信息")
    @GetMapping("getInterviewInfo")
    public Result getInterviewInfo(Long recordId){
        return Result.success().put("data", recordService.getInterviewInfo(recordId));
    }

    @ApiOperation("添加或修改面试记录")
    @PostMapping("saveInterview")
    public Result saveInterview(@RequestBody InterviewRecord interviewRecord) {
        return recordService.saveInterview(interviewRecord);
    }

    @Login
    @GetMapping("userUpdateInter")
    @ApiOperation("用户同意或拒绝")
    public Result userUpdateInter(@RequestAttribute("userId")Long userId,Long recordId,Integer type){
        return recordService.userUpdateInter(userId,recordId,type);
    }


    @ApiOperation("是否可以发送简历")
    @GetMapping("isSendView")
    public Result isSendView(Long postPushId,Long userId) {
        return recordService.isSendView(postPushId,userId);
    }

//    @Login
//    @PostMapping("addInterview")
//    @ApiOperation("新增面试邀请")
//    public  Result addInterview(@RequestAttribute("userId")Long userId,@RequestBody InterviewRecord interviewRecord){
//        interviewRecord.setUserId(userId);
//        interviewRecordService.saveOrUpdate(interviewRecord);
//        return  Result.success();
//    }

    @Login
    @GetMapping("selectInterviewListOfUser")
    @ApiOperation("用户搜索面试列表")
    public  Result selectInterviewList(@RequestAttribute("userId")Long userId){
        return Result.success().put("data",interviewRecordService.selectInterviewList(userId));
    }

    @Login
    @PostMapping("addHrPhone")
    @ApiOperation("新增岗位联系人")
    public  Result addHrPhone (@RequestAttribute("userID")Long userId, @RequestBody HrPhone hrPhone){
        hrPhone.setUserId(Math.toIntExact(userId));
        hrPhone.setIsUse(1);
        hrPhoneService.saveOrUpdate(hrPhone);
        return  Result.success();
    }
    @Login
    @PostMapping("selectHrPhone")
    @ApiOperation("新增岗位联系人")
    public  Result selectHrPhone (@RequestAttribute("userID")Long userId){
        return Result.success().put("data",hrPhoneService.getBaseMapper().selectList(new QueryWrapper<HrPhone>().eq("user_id",userId).eq("is_use",1)));
    }
    @Login
    @PostMapping("deleteHrPhone")
    @ApiOperation("删除联系人")
    public  Result deleteHrPhone ( @RequestBody HrPhone hrPhone){
        HrPhone hrPhone1 =hrPhoneService.getById(hrPhone.getHrPhoneId());
        hrPhone1.setIsUse(0);
        hrPhoneService.updateById(hrPhone1);
        return Result.success();
    }


}

