package jnpf.cultivate.v2.controller.app.promotion;

import jnpf.base.ActionResult;
import jnpf.cultivate.v2.service.V2CultivatePromotionService;
import jnpf.model.cultivate.v2.promotion.req.V2CultivatePromotionPhaseStateForApp;
import jnpf.model.cultivate.v2.promotion.req.V2CultivatePromotionPositionDetailForApp;
import jnpf.model.cultivate.v2.promotion.req.V2CultivatePromotionSelectPositionReq;
import jnpf.model.cultivate.v2.promotion.vo.AppCultivatePromotionPositionDetailVo;
import jnpf.model.cultivate.v2.promotion.vo.MyCultivatePromotionListVo;
import jnpf.model.cultivate.v2.promotion.vo.PromotionPhaseVo;
import jnpf.model.cultivate.v2.promotion.vo.UserPromotionDetailVo;
import jnpf.util.UserProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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


/**
 * app学习地图模块
 *
 * @author xgl
 */
@RestController
@RequestMapping("/v2/app/promotion")
public class V2CultivatePromotionAppController {
    /**
     * 服务对象
     */
    @Autowired
    private V2CultivatePromotionService promotionService;


    /**
     * 获取我的所有学习地图列表
     *
     * @return
     */
    @GetMapping("/query-my-all-promotion-list")
    public ActionResult<List<MyCultivatePromotionListVo>> queryMyAllPromotionList() {
        return ActionResult.success("成功", promotionService.queryMyAllPromotionList(UserProvider.getUser().getUserId()));
    }


    /**
     * 选定一个学习地图
     *
     * @return
     */
    @PutMapping("/select-promotion/{promotionId}")
    public ActionResult<Void> selectPromotion(@PathVariable("promotionId") String promotionId) {
        promotionService.selectPromotion(UserProvider.getUser().getUserId(), promotionId);
        return ActionResult.success("成功");
    }

    /**
     * 学习地图的一个阶段，选定学习的岗位
     *
     * @return
     */
    @PostMapping("/record-select-position")
    public ActionResult<Void> recordSelectPosition(@Validated @RequestBody V2CultivatePromotionSelectPositionReq req) {
        promotionService.recordSelectPosition(req);
        return ActionResult.success();
    }

    /**
     * 查询学习地图阶段信息（userId+promotionId+level）
     *
     * @param userId      用户id
     * @param promotionId 学习地图id
     * @param level       阶段
     * @return 返回配置的岗位&职级信息 已经选择的岗位&职级信息
     */
    @GetMapping("/guery-promotion-info-for-level")
    public ActionResult<PromotionPhaseVo> queryPromotionInfoForLevel(@RequestParam("userId") String userId,
                                                                     @RequestParam("promotionId") String promotionId,
                                                                     @RequestParam("level") Integer level) {
        return ActionResult.success(promotionService.queryPromotionInfoForLevel(userId, promotionId, level));
    }


    /**
     * 查询地图岗位学习详情（userid + positionId + level）
     *
     * @param req 请求参数
     * @return 返回岗位学习详情
     */
    @GetMapping("/promotion-position-study-detail")
    public ActionResult<AppCultivatePromotionPositionDetailVo> positionStudyDetail(V2CultivatePromotionPositionDetailForApp req) {
        return ActionResult.success("成功", promotionService.getPositionStudyDetail(req));
    }


    /**
     * 查询地图阶段完成情况（promotionId + level + userId）
     *
     * @param req 请求参数
     * @return 状态 0-未完成 1-已完成
     */
    @GetMapping("/promotion-level-status")
    public ActionResult<Integer> promotionLevelStatus(V2CultivatePromotionPhaseStateForApp req) {
        return ActionResult.success("成功", promotionService.promotionLevelStatus(req));
    }

    /**
     * 根据用户ID和学习地图ID查询指定学习地图及分阶段岗位信息
     *
     * @param userId      用户ID
     * @param promotionId 学习地图ID
     * @return 用户学习地图详情，包含该学习地图的各阶段岗位信息
     */
    @GetMapping("/user-promotion-detail")
    public ActionResult<UserPromotionDetailVo> getUserPromotionDetail(@RequestParam("userId") String userId,
                                                                       @RequestParam("promotionId") String promotionId) {
        return ActionResult.success("成功", promotionService.getUserPromotionDetail(userId, promotionId));
    }

}