package com.reading.platform.controller.admin;

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/admin/packages")
@RequiredArgsConstructor
@RequireRole(UserRole.ADMIN)
public class AdminCoursePackageController {

    private final CoursePackageService coursePackageService;

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

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

    @Operation(summary = "创建课程包")
    @PostMapping
    public Result<CoursePackage> createPackage(@RequestBody CoursePackage pkg) {
        return Result.success(coursePackageService.createPackage(pkg));
    }

    @Operation(summary = "更新课程包")
    @PutMapping("/{id}")
    public Result<CoursePackage> updatePackage(@PathVariable String id, @RequestBody CoursePackage pkg) {
        return Result.success(coursePackageService.updatePackage(id, pkg));
    }

    @Operation(summary = "删除课程包")
    @DeleteMapping("/{id}")
    public Result<Void> deletePackage(@PathVariable String id) {
        coursePackageService.deletePackage(id);
        return Result.success();
    }

    // 注意：课程包状态管理已移至套餐（ProductBundle）
    // 以下方法已废弃，请使用 /api/v1/admin/bundles 相关接口
}
