package com.reading.platform.controller.teacher;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.reading.platform.common.annotation.RequireRole;
import com.reading.platform.common.enums.UserRole;
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.SchoolCourse;
import com.reading.platform.service.SchoolCourseService;
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 = "教师 - 校本课程", description = "校本课程接口（教师专用）")
@RestController
@RequestMapping("/api/v1/teacher/school-courses")
@RequiredArgsConstructor
@RequireRole(UserRole.TEACHER)
public class TeacherSchoolCourseController {

    private final SchoolCourseService schoolCourseService;

    @Operation(summary = "获取校本课程")
    @GetMapping
    public Result<PageResult<SchoolCourse>> getCourses(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "20") int pageSize,
            @RequestParam(required = false) String keyword) {
        String tenantId = SecurityUtils.getCurrentTenantId();
        Page<SchoolCourse> page = schoolCourseService.getCourses(pageNum, pageSize, tenantId, keyword);
        return Result.success(PageResult.of(page));
    }

    @Operation(summary = "根据ID获取校本课程")
    @GetMapping("/{id}")
    public Result<SchoolCourse> getCourse(@PathVariable String id) {
        return Result.success(schoolCourseService.getCourseById(id));
    }
}
