package jnpf.cultivate.controller.web.promotion;


import io.swagger.v3.oas.annotations.Parameter;
import jnpf.base.ActionResult;
import jnpf.cultivate.service.FtbCultivatePromotionMemberService;
import jnpf.model.cultivate.dto.promotion.FtbCultivatePromotionMemberDto;
import jnpf.model.cultivate.vo.promotion.FtbCultivateMeberVO;
import jnpf.model.cultivate.vo.promotion.FtbCultivatePromotionVO;
import jnpf.permission.model.userrelation.UserRelationPositionGrades;
import org.springframework.web.bind.annotation.*;

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

/**
 * web晋升通道成员管理模块
 * @author penghao
 */
@RestController
@RequestMapping("/cul_pro_member")
public class FtbCultivatePromotionMemberController {
    /**
     * 服务对象
     */
    @Resource
    public FtbCultivatePromotionMemberService promotionMemberService;


    /**
     * 根据当前晋升通道id查询通道成员(包含未启用的通道成员,已启用的)
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @Parameter(name = "id", description = "通道id主键", required = true)
   // @SaCheckPermission("promotionChannelMgrs::btn_channel_member")
    public ActionResult<FtbCultivateMeberVO> queryChannelMembers(@PathVariable("id") String id){
        FtbCultivateMeberVO meberVO =  promotionMemberService.queryChannelMembers(id);
        return ActionResult.success(meberVO);
    }

    /**
     * 拖动添加成员启用对应晋升通道
     * @param dto 用户id
     * @return
     */
    @PostMapping("/addMembersToProChannel")
    public ActionResult<Boolean> addMembersToProChannel(@RequestBody FtbCultivatePromotionMemberDto dto){
       promotionMemberService.addMembersToProChannel(dto);
        return ActionResult.success();
    }
    /**
     * 拖动删除成员启用对应晋升通道
     * @param userIds 用户id
     * @return
     */
    @PutMapping("/deleteMembersToProChannel")
    public ActionResult<Boolean> deleteMembersToProChannel(@RequestBody List<String> userIds){
        promotionMemberService.deleteMembersToProChannel(userIds);
        return ActionResult.success();
    }

    /**
     * 更改组织信息删除成员启用对应晋升通道和岗位学习对应职等开启的课程
     * @param organizeId
     * @param userRelationPositionGrades
     * @return
     */
    @PutMapping("/deleteRelation/{organizeId}")
    public ActionResult<Boolean> deleteRelation(@PathVariable("organizeId") String organizeId,
                                                @RequestBody UserRelationPositionGrades userRelationPositionGrades){
        promotionMemberService.deleteRelation(organizeId,userRelationPositionGrades);
        return ActionResult.success();
    }

    /**
     * 根据用户ID 或者岗位id 获取对应的晋升通道。
     * 如果用户不存在或相关数据有问题，将返回失败的ActionResult。
     *
     * @param userId 用户ID
     * @return 用户ID对应的晋升通道列表
     */
    @GetMapping("/userId")
    public ActionResult<FtbCultivatePromotionVO> getPromotionsByUserId(@RequestParam(value = "userId" ,required = false) String userId,
                                                                       @RequestParam(value = "postId",required = false) String postId) {
            FtbCultivatePromotionVO promotionVO = promotionMemberService.queryPromotionByUser(userId,postId);
            // 记录日志或统计数据
            return ActionResult.success(promotionVO);
    }




}
