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.InterviewRecord;
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;
    @Login
    @ApiOperation("获取面试记录列表")
    @GetMapping("interviewList")
    public Result interviewList(@RequestAttribute("userId")Long userId, Integer page, Integer limit, InterviewRecord interviewRecord) {
        UserEntity userEntity = userService.getById(userId);
        if(userEntity.getUserType()==1){
            interviewRecord.setUserId(userId);
        }else {
            Company company = companyService.getOne(new QueryWrapper<Company>().eq("user_id", userId));
            interviewRecord.setCompanyId(company.getCompanyId());
        }
        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);
    }
}

