package jnpf.cultivate.controller.app.promotion;

import io.swagger.v3.oas.annotations.Operation;
import jnpf.base.ActionResult;
import jnpf.cultivate.service.FtbCultivatePromotionPostService;
import jnpf.model.cultivate.dto.promotion.FtbCultivatePromotionForAppDto;
import jnpf.model.cultivate.vo.promotion.FtbCultivatePromotionForAppVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *  app晋升通道级别模块
    *
 */
@RestController
@RequestMapping("/cul-post-app")
public class FtbCulProPostForAppController {

    @Resource
    private FtbCultivatePromotionPostService postService;


    /**
     * 根据当前用户id和岗位id 判断 当前是否启用 晋升通道
     *
     * @param userId 当前用户id
     * @param postId 岗位id
     * @return false为未开启,true为开启
     *
     */
    @GetMapping("/queryChannelIsEnb")
    @Operation(method = "根据当前用户id和岗位id查询当前是否启用 晋升通道")
    public ActionResult<Boolean> checkWhetherThePromotionChannelIsEnabled(
            @RequestParam("userId") String userId,
            @RequestParam("postId") String postId){
        boolean isEnb = postService.checkWhetherThePromotionChannelIsEnabled(userId,postId);
        return ActionResult.success(isEnb);
    }



    /**
     * 根据当前用户id和岗位id查询当前已启动晋升通道和其他可选晋升通道
     *
     * @param userId 用户id
     * @param postId 岗位职能id
     * @return {@link ActionResult}<{@link FtbCultivatePromotionForAppVO}>
     */
    @GetMapping("/queryById")
    @Operation(method = "根据当前用户id和岗位id查询当前已启动晋升通道和其他可选晋升通道")
    public ActionResult<FtbCultivatePromotionForAppVO> queryThePromotedChannelsThatAreInitiated(
            @RequestParam("userId") String userId,
            @RequestParam("postId") String postId){
        FtbCultivatePromotionForAppVO promotionVO =  postService.queryThePromotedChannelsThatAreInitiated(userId,postId);
        return ActionResult.success(promotionVO);
    }

    /**
     * 更改启用状态
     *
     * @param forAppDto
     */
    @PutMapping("/changeStatus")
    @Operation(method = "更改启用状态")
    public ActionResult<String> changeTheEnablementStatus(@RequestBody FtbCultivatePromotionForAppDto forAppDto){
        String s = postService.changeTheEnablementStatus(forAppDto);
        return ActionResult.success(s);
    }


    /**
     * 查询当前用户是否允许修改通道
     *
     */
    @GetMapping("/userIsAllowed/{userId}")
    @Operation(method = "查询当前用户是否允许修改通道")
    public ActionResult<Integer> userIsAllowed(@PathVariable("userId") String userId){
        return ActionResult.success(postService.userIsAllowed(userId));
    }

    /**
     * 修改是否允许下属变更
     * 此接口用于修改是否允许下属变更
     *
     * @param forAppDto 修改设置的请求数据
     * @return 操作结果
     */
    @PutMapping("/changeIsAllowed")
    @Operation(method = "更改是否允许下属变更")
    public ActionResult<String> changeWhetherTheChangeIsAllowed(@RequestBody FtbCultivatePromotionForAppDto forAppDto){
        postService.changeWhetherTheChangeIsAllowed(forAppDto);
        return ActionResult.success();
    }
}
