package jnpf.cultivate.controller.app.learn;

import jnpf.base.ActionResult;
import jnpf.base.vo.PageListVO;
import jnpf.cultivate.service.FtbCultivateMyLearnTaskInfoService;
import jnpf.exception.HandleException;
import jnpf.model.cultivate.dto.learn.FtbCultivateLearnTaskListDto;
import jnpf.model.cultivate.vo.course.app.FtbAppTaskCountVO;
import jnpf.model.cultivate.vo.course.app.FtbGlobalCurriculumAppVO;
import jnpf.model.cultivate.vo.learn.FtbCultivateLearnTaskExamInfoVO;
import jnpf.model.cultivate.vo.learn.FtbCultivateLearnTaskIdentificationInfoVO;
import jnpf.model.cultivate.vo.learn.FtbCultivateLearnTaskInfoForAppVO;
import jnpf.model.cultivate.vo.learn.FtbCultivateMyLearnTaskListVO;
import jnpf.util.UserProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

/**
 * app我的培训任务
 * @Author: peng.hao
 * @create: 2024/9/9:11:21
 */
@Slf4j
@RestController
@RequestMapping("/app/my-learn-task")
public class FtbCultivateMyLearnTaskForAppController {

    @Resource
    private FtbCultivateMyLearnTaskInfoService cultivateMyLearnTaskInfoService;

    /**
     * 培训任务列表
     */
    @GetMapping("/getTaskList")
    public ActionResult<PageListVO<FtbCultivateMyLearnTaskListVO>> taskList(FtbCultivateLearnTaskListDto taskListDto) {
        return ActionResult.success(cultivateMyLearnTaskInfoService.taskList(taskListDto));
    }

    /**
     * 立即完成
     */
    @PutMapping("/completeTask/{taskId}")
    public ActionResult<Void> completeTask(@PathVariable("taskId") String taskId) {
        cultivateMyLearnTaskInfoService.completeTask(taskId);
        return ActionResult.success();
    }

    /**
     * 培训任务列表计数
     */
    @GetMapping("/getTaskCount")
    public ActionResult<Map<String,Integer>> taskListCount(@RequestParam(value = "keyWords",defaultValue = "",required = false) String keyWords) {
        return ActionResult.success(cultivateMyLearnTaskInfoService.taskListCount(keyWords));
    }


    /**
     * 任务详情(基本信息)
     * @param taskId 任务id
     */
    @GetMapping("/getTaskInfo")
    public ActionResult<FtbCultivateLearnTaskInfoForAppVO> getLearnTaskInfoForApp(@RequestParam("taskId") String taskId) {
        return ActionResult.success(cultivateMyLearnTaskInfoService.getLearnTaskInfoForApp(taskId));
    }

    /**
     * 任务课程列表
     * @param taskId 任务主键ID(必传)
     * @param compulsory 是否必修，0必修，1选修
     */
    @GetMapping("/task-course-list")
    public ActionResult<List<FtbGlobalCurriculumAppVO>> taskCourseList(@RequestParam("taskId") String taskId,@RequestParam("compulsory") Integer compulsory) throws HandleException {
        // 当前用户id
        String userId = UserProvider.getUser().getUserId();
        return ActionResult.success(cultivateMyLearnTaskInfoService.taskCourseList(taskId, userId,compulsory));
    }


    /**
     * 任务课程(数量)
     * @param taskId 任务主键ID(必传)
     */
    @GetMapping("/task-course-num")
    public ActionResult<FtbAppTaskCountVO> taskCourseNum(@RequestParam("taskId") String taskId) throws HandleException {
        // 当前用户id
        String userId = UserProvider.getUser().getUserId();
        return ActionResult.success(cultivateMyLearnTaskInfoService.taskCourseNum(taskId, userId));
    }
    /**
     * 任务考试列表
     * @param taskId 任务主键ID(必传)
     */
    @GetMapping("/task-exam-list")
    public ActionResult<List<FtbCultivateLearnTaskExamInfoVO>> taskExamList(@RequestParam("taskId") String taskId) {
        // 当前用户id
        String userId = UserProvider.getUser().getUserId();
        return ActionResult.success(cultivateMyLearnTaskInfoService.taskExamList(taskId, userId));
    }

    /**
     * 任务实操鉴定列表
     * @param taskId 任务主键ID(必传)
     */
    @GetMapping("/task-identification-list")
    public ActionResult<List<FtbCultivateLearnTaskIdentificationInfoVO>> taskIdentificationList(@RequestParam("taskId") String taskId) {
        // 当前用户id
        String userId = UserProvider.getUser().getUserId();
        return ActionResult.success(cultivateMyLearnTaskInfoService.taskIdentificationList(taskId, userId));
    }


}
