package jnpf.cultivate.controller.web.apply;

import io.swagger.v3.oas.annotations.Operation;
import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.service.FtbCultivatePromotionPostApplyService;
import jnpf.model.cultivate.CultivatePage;
import jnpf.model.cultivate.dto.apply.FtbCultivatePromotionPostApplyCreateDto;
import jnpf.model.cultivate.dto.apply.FtbCultivatePromotionPostApplyDto;
import jnpf.model.cultivate.vo.apply.FtbCultivatePromotionPostApplyVO;
import jnpf.model.cultivate.vo.apply.FtbCultivatePromotionPostApplyWithPerVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
*  web岗位晋升申请模块
* @author penghao
*/
@RestController
@RequestMapping("/cul-post-apply")
public class FtbCultivatePromotionPostApplyController {


    @Resource
    FtbCultivatePromotionPostApplyService postApplyService;


    /**
     * 获取岗位申请列表
     * @param dto 岗位申请查询参数
     * @param page 分页信息
     * @return 岗位申请列表结果
     */
    @GetMapping("/getList")
    @Operation(summary ="查看岗位申请列表")
    public ActionResult<PageListVO<FtbCultivatePromotionPostApplyVO>> getList(FtbCultivatePromotionPostApplyDto dto, CultivatePage page) {
        PageListVO<FtbCultivatePromotionPostApplyVO> voPageListVO = postApplyService.getList(dto, page);
        return ActionResult.success(voPageListVO);
    }


    /**
     * 初始化岗位申请
     *
     * @param createDto 岗位申请创建数据传输对象
     * @return
     */
    @PostMapping("/initPromApplication")
    @Operation(summary = "初始化岗位申请")
    //@SaCheckPermission("jobPromotionApplications::btn_promotion_application")
    public ActionResult<String> initiateAPromotionApplication(@Validated @RequestBody FtbCultivatePromotionPostApplyCreateDto createDto) {
        createDto.setSource(0);
        postApplyService.initiateAPromotionApplication(createDto);
        return ActionResult.success();
    }


    /**
     * 查询岗位申请详情
     * @param dto 岗位申请数据传输对象
     * @return ActionResult<FtbCultivatePromotionPostApplyWithPerVO> 响应结果对象，包含岗位申请及相关信息
     */
    @GetMapping("/viewPromApplication")
    @Operation(summary = "查询岗位申请详情")
    //@SaCheckPermission("jobPromotionApplications::btn_view")
    public ActionResult<FtbCultivatePromotionPostApplyWithPerVO> viewPromotionApplications(FtbCultivatePromotionPostApplyDto dto) {
        FtbCultivatePromotionPostApplyWithPerVO withPerVO =  postApplyService.viewPromotionApplications(dto, "0");
        return ActionResult.success(withPerVO);
    }


    /**
     * 审核岗位申请的接口
     * @param dto 岗位申请数据传输对象
     * @return 审核结果
     */
    @PutMapping("/auditPromApplication")
    @Operation(summary = "审核岗位申请")
    public ActionResult<String> auditPromotionPostApplication(@RequestBody FtbCultivatePromotionPostApplyDto dto) {
        postApplyService.auditPromotionPostApplication(dto);
        return ActionResult.success();
    }

    /**
     * 获取是否有人岗位职等的晋升申请
     * @param postId 公司岗位ID
     * @param grandId 职等ID
     * @param userId 用户ID
     * @return 成功结果
     */
    @GetMapping("/userIsHasApply")
    @Operation(summary = "查看当前的人岗位职等是否存在晋升申请")
    public ActionResult<Boolean> isThereAnAppForThePosLevel(@RequestParam("postId") String postId,
                                                                        @RequestParam("grandId") String grandId,
                                                                        @RequestParam("userId") String userId) {
        return ActionResult.success(postApplyService.isThereAnAppForThePosLevel(postId,grandId,userId));
    }





}
