import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  ParseIntPipe,
  UseGuards,
} from '@nestjs/common';
import { ThemeService } from './theme.service';
import { JwtAuthGuard } from '../common/guards/jwt-auth.guard';
import { RolesGuard } from '../common/guards/roles.guard';
import { Roles } from '../common/decorators/roles.decorator';

@Controller('admin/themes')
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles('admin')
export class ThemeController {
  constructor(private readonly themeService: ThemeService) {}

  @Get()
  async findAll() {
    return this.themeService.findAll();
  }

  @Get(':id')
  async findOne(@Param('id', ParseIntPipe) id: number) {
    return this.themeService.findOne(id);
  }

  @Post()
  async create(
    @Body() body: { name: string; description?: string; sortOrder?: number },
  ) {
    return this.themeService.create(body);
  }

  @Put(':id')
  async update(
    @Param('id', ParseIntPipe) id: number,
    @Body()
    body: { name?: string; description?: string; sortOrder?: number; status?: string },
  ) {
    return this.themeService.update(id, body);
  }

  @Delete(':id')
  async remove(@Param('id', ParseIntPipe) id: number) {
    return this.themeService.remove(id);
  }

  @Put('reorder')
  async reorder(@Body() body: { ids: number[] }) {
    return this.themeService.reorder(body.ids);
  }
}
