package com.reading.platform.controller.admin;

import com.reading.platform.common.annotation.RequireRole;
import com.reading.platform.common.enums.UserRole;
import com.reading.platform.common.response.Result;
import com.reading.platform.entity.Theme;
import com.reading.platform.service.ThemeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "管理员 - 主题", description = "主题管理接口（管理员专用）")
@RestController
@RequestMapping("/api/v1/admin/themes")
@RequiredArgsConstructor
@RequireRole(UserRole.ADMIN)
public class AdminThemeController {

    private final ThemeService themeService;

    @Operation(summary = "获取所有主题")
    @GetMapping
    public Result<List<Theme>> getThemes(@RequestParam(required = false) Boolean enabledOnly) {
        return Result.success(themeService.getAllThemes(enabledOnly));
    }

    @Operation(summary = "根据ID获取主题")
    @GetMapping("/{id}")
    public Result<Theme> getTheme(@PathVariable String id) {
        return Result.success(themeService.getThemeById(id));
    }

    @Operation(summary = "创建主题")
    @PostMapping
    public Result<Theme> createTheme(@RequestBody Theme theme) {
        return Result.success(themeService.createTheme(theme));
    }

    @Operation(summary = "更新主题")
    @PutMapping("/{id}")
    public Result<Theme> updateTheme(@PathVariable String id, @RequestBody Theme theme) {
        return Result.success(themeService.updateTheme(id, theme));
    }

    @Operation(summary = "删除主题")
    @DeleteMapping("/{id}")
    public Result<Void> deleteTheme(@PathVariable String id) {
        themeService.deleteTheme(id);
        return Result.success();
    }
}
