package com.reading.platform.controller.parent;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.reading.platform.common.response.PageResult;
import com.reading.platform.common.response.Result;
import com.reading.platform.common.security.SecurityUtils;
import com.reading.platform.entity.Task;
import com.reading.platform.service.TaskService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Parent - Task", description = "Task APIs for Parent")
@RestController
@RequestMapping("/api/parent/tasks")
@RequiredArgsConstructor
public class ParentTaskController {

    private final TaskService taskService;

    @Operation(summary = "Get task by ID")
    @GetMapping("/{id}")
    public Result<Task> getTask(@PathVariable Long id) {
        return Result.success(taskService.getTaskById(id));
    }

    @Operation(summary = "Get tasks by student ID")
    @GetMapping("/student/{studentId}")
    public Result<PageResult<Task>> getTasksByStudent(
            @PathVariable Long studentId,
            @RequestParam(required = false) Integer pageNum,
            @RequestParam(required = false) Integer pageSize,
            @RequestParam(required = false) String status) {
        Page<Task> page = taskService.getTasksByStudentId(studentId, pageNum, pageSize, status);
        return Result.success(PageResult.of(page));
    }

    @Operation(summary = "Complete task")
    @PostMapping("/{taskId}/complete")
    public Result<Void> completeTask(
            @PathVariable Long taskId,
            @RequestParam Long studentId,
            @RequestParam(required = false) String content,
            @RequestParam(required = false) String attachments) {
        taskService.completeTask(taskId, studentId, content, attachments);
        return Result.success();
    }

}
