package jnpf.cultivate.controller.web.learn;

import jnpf.base.ActionResult;
import jnpf.cultivate.service.FtbCultivateLearnTaskInfoContentService;
import jnpf.model.cultivate.dto.learn.FtbCultivateLearnAllocationDTO;
import jnpf.model.cultivate.dto.learn.FtbCultivateLearnTaskInfoDto;
import jnpf.model.cultivate.vo.learn.FtbLearnQueryTaskDetailsEditingVO;
import jnpf.valid.ValidInsert;
import jnpf.valid.ValidUpdate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.groups.Default;
import java.util.List;

/**
 * web学习任务模块
 *
 * @Author: wcx
 * @create: 2024/9/9
 */
@RestController
@Slf4j
@RequestMapping("/web/learn-task")
public class FtbCultivateLearnTaskContentController {

    @Resource
    private FtbCultivateLearnTaskInfoContentService ftbCultivateLearnTaskInfoContentService;

    /**
     * 保存学习任务
     *
     * @param taskInfoDto
     * @return
     */
    @PostMapping("/save-learn-task")
    public ActionResult<Void> saveLearnTaskList(@RequestBody @Validated(value = {Default.class, ValidInsert.class}) FtbCultivateLearnTaskInfoDto taskInfoDto) {
        ftbCultivateLearnTaskInfoContentService.saveLearnTaskList(taskInfoDto);
        return ActionResult.success();
    }

    /**
     * 编辑学习任务
     *
     * @param taskInfoDto
     * @return
     */
    @PostMapping("/update-learn-task")
    public ActionResult<Void> updateLearnTaskList(@RequestBody @Validated(value = {Default.class, ValidUpdate.class}) FtbCultivateLearnTaskInfoDto taskInfoDto) {
        ftbCultivateLearnTaskInfoContentService.updateLearnTaskList(taskInfoDto);
        return ActionResult.success();
    }

    /**
     * 任务分配-已分配的人员集合
     *
     * @param taskId 任务主键ID(必传)
     * @return {@link ActionResult }
     */
    @GetMapping("/collection-of-assigned-people")
    public ActionResult<List<String>> getLearnTaskAllocationList(String taskId) {
        List<String> result = ftbCultivateLearnTaskInfoContentService.getLearnTaskAllocationList(taskId);
        return ActionResult.success(result);
    }

    /**
     * 分配任务
     *
     * @return {@link ActionResult }
     */
    @PostMapping("/allocation-task")
    public ActionResult allocation(@RequestBody @Validated FtbCultivateLearnAllocationDTO allocationDTO) {
        ftbCultivateLearnTaskInfoContentService.allocation(allocationDTO);
        return ActionResult.success();
    }

    /**
     * 中止任务
     *
     * @param id 任务主键ID(必传)
     * @return {@link ActionResult }
     */
    @PutMapping("/abort-task/{id}")
    public ActionResult abort(@PathVariable("id") String id) {
        ftbCultivateLearnTaskInfoContentService.abort(id);
        return ActionResult.success();
    }

    /**
     * 删除任务
     *
     * @param id 任务主键ID(必传)
     * @return {@link ActionResult }
     */
    @DeleteMapping("/delete-task/{id}")
    public ActionResult deleteTask(@PathVariable("id") String id) {
        ftbCultivateLearnTaskInfoContentService.deleteTask(id);
        return ActionResult.success();
    }

    /**
     * 编辑时查询任务详情
     *
     * @param id 任务主键ID(必传)
     * @return {@link ActionResult }
     */
    @GetMapping("/query-task-details-while-editing/{id}")
    public ActionResult<FtbLearnQueryTaskDetailsEditingVO> queryTaskDetailsWhileEditing(@PathVariable("id") String id) {
        FtbLearnQueryTaskDetailsEditingVO ftbLearnQueryTaskDetailsEditingVO = ftbCultivateLearnTaskInfoContentService.queryTaskDetailsWhileEditing(id);
        return ActionResult.success(ftbLearnQueryTaskDetailsEditingVO);
    }

}
