package com.reading.platform.controller.school;

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.entity.CoursePackage;
import com.reading.platform.service.CoursePackageService;
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/school")
@RequiredArgsConstructor
@RequireRole(UserRole.SCHOOL)
public class SchoolCoursePackageController {

    private final CoursePackageService coursePackageService;

    @Operation(summary = "获取可用课程包列表（兼容旧路径 /packages）")
    @GetMapping("/packages")
    public Result<PageResult<CoursePackage>> getPackagesAlias(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "20") int pageSize,
            @RequestParam(required = false) String keyword) {
        Page<CoursePackage> page = coursePackageService.getPackages(pageNum, pageSize, keyword);
        return Result.success(PageResult.of(page));
    }

    @Operation(summary = "获取可用课程包列表")
    @GetMapping("/course-packages")
    public Result<PageResult<CoursePackage>> getPackages(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "20") int pageSize,
            @RequestParam(required = false) String keyword) {
        Page<CoursePackage> page = coursePackageService.getPackages(pageNum, pageSize, keyword);
        return Result.success(PageResult.of(page));
    }

    @Operation(summary = "根据 ID 获取课程包（兼容旧路径 /packages/{id}）")
    @GetMapping("/packages/{id}")
    public Result<CoursePackage> getPackageAlias(@PathVariable String id) {
        return Result.success(coursePackageService.getPackageById(id));
    }

    @Operation(summary = "根据 ID 获取课程包")
    @GetMapping("/course-packages/{id}")
    public Result<CoursePackage> getPackage(@PathVariable String id) {
        return Result.success(coursePackageService.getPackageById(id));
    }
}
