package org.xyzh.study.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.xyzh.api.study.task.LearningTaskService;
import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.dto.study.TbLearningTask;
import org.xyzh.common.dto.study.TbTaskUser;
import org.xyzh.common.dto.study.TbTaskCourse;
import org.xyzh.common.dto.study.TbTaskResource;

/**
 * @description 学习任务控制器
 * @filename LearningTaskController.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-10-15
 */
@RestController
@RequestMapping("/study/task")
public class LearningTaskController {
    private static final Logger logger = LoggerFactory.getLogger(LearningTaskController.class);

    @Autowired
    private LearningTaskService learningTaskService;

    /**
     * 获取任务列表
     */
    @GetMapping("/list")
    public ResultDomain<TbLearningTask> getTaskList(TbLearningTask filter) {
        return learningTaskService.getTaskList(filter);
    }

    /**
     * 根据ID获取任务详情
     */
    @GetMapping("/{taskID}")
    public ResultDomain<TbLearningTask> getTaskById(@PathVariable String taskID) {
        return learningTaskService.getTaskById(taskID);
    }

    /**
     * 创建任务
     */
    @PostMapping("/create")
    public ResultDomain<TbLearningTask> createTask(@RequestBody TbLearningTask task) {
        return learningTaskService.createTask(task);
    }

    /**
     * 更新任务
     */
    @PutMapping("/update")
    public ResultDomain<TbLearningTask> updateTask(@RequestBody TbLearningTask task) {
        return learningTaskService.updateTask(task);
    }

    /**
     * 删除任务
     */
    @DeleteMapping("/{taskID}")
    public ResultDomain<Boolean> deleteTask(@PathVariable String taskID) {
        return learningTaskService.deleteTask(taskID);
    }

    /**
     * 更新任务状态
     */
    @PutMapping("/{taskID}/status")
    public ResultDomain<TbLearningTask> updateTaskStatus(
            @PathVariable String taskID,
            @RequestParam Integer status) {
        return learningTaskService.updateTaskStatus(taskID, status);
    }

    /**
     * 获取任务用户列表
     */
    @GetMapping("/{taskID}/users")
    public ResultDomain<TbTaskUser> getTaskUsers(@PathVariable String taskID) {
        return learningTaskService.getTaskUsers(taskID);
    }

    /**
     * 分配任务给用户
     */
    @PostMapping("/{taskID}/assign")
    public ResultDomain<TbTaskUser> assignTaskToUser(
            @PathVariable String taskID,
            @RequestParam String userID) {
        return null;
        // return learningTaskService.assignTaskToUser(taskID, userID);
    }

    /**
     * 从用户移除任务
     */
    @DeleteMapping("/{taskID}/user/{userID}")
    public ResultDomain<Boolean> removeTaskFromUser(
            @PathVariable String taskID,
            @PathVariable String userID) {
        return null;
        // return learningTaskService.removeTaskFromUser(taskID, userID);
    }

    /**
     * 获取任务课程列表
     */
    @GetMapping("/{taskID}/courses")
    public ResultDomain<TbTaskCourse> getTaskCourses(@PathVariable String taskID) {
        return learningTaskService.getTaskCourses(taskID);
    }

    /**
     * 添加课程到任务
     */
    @PostMapping("/{taskID}/course")
    public ResultDomain<TbTaskCourse> addCourseToTask(
            @PathVariable String taskID,
            @RequestParam String courseID) {
        return null;
        // return learningTaskService.addCourseToTask(taskID, courseID);
    }

    /**
     * 从任务移除课程
     */
    @DeleteMapping("/{taskID}/course/{courseID}")
    public ResultDomain<Boolean> removeCourseFromTask(
            @PathVariable String taskID,
            @PathVariable String courseID) {
        return null;
        // return learningTaskService.removeCourseFromTask(taskID, courseID);
    }

    /**
     * 获取任务资源列表
     */
    @GetMapping("/{taskID}/resources")
    public ResultDomain<TbTaskResource> getTaskResources(@PathVariable String taskID) {
        return learningTaskService.getTaskResources(taskID);
    }

    /**
     * 添加资源到任务
     */
    @PostMapping("/{taskID}/resource")
    public ResultDomain<TbTaskResource> addResourceToTask(
            @PathVariable String taskID,
            @RequestParam String resourceID) {
        return null;
        // return learningTaskService.addResourceToTask(taskID, resourceID);
    }

    /**
     * 从任务移除资源
     */
    @DeleteMapping("/{taskID}/resource/{resourceID}")
    public ResultDomain<Boolean> removeResourceFromTask(
            @PathVariable String taskID,
            @PathVariable String resourceID) {
        return null;
        // return learningTaskService.removeResourceFromTask(taskID, resourceID);
    }
}
