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

@ApiTags('Banners')
@Controller()
export class BannersController {
  constructor(private bannersService: BannersService) {}

  @Get('banners')
  findAll() {
    return this.bannersService.findAll();
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Get('admin/banners')
  adminFindAll() {
    return this.bannersService.adminFindAll();
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Post('admin/banners')
  create(@Body() data: { title?: string; image: string; link?: string; orderNo?: number; status?: boolean }) {
    return this.bannersService.create(data);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Put('admin/banners/:id')
  update(@Param('id') id: string, @Body() data: { title?: string; image?: string; link?: string; orderNo?: number; status?: boolean }) {
    return this.bannersService.update(+id, data);
  }

  @ApiBearerAuth()
  @UseGuards(JwtAuthGuard, RolesGuard)
  @Roles('SUPER_ADMIN', 'ADMIN')
  @Delete('admin/banners/:id')
  remove(@Param('id') id: string) {
    return this.bannersService.remove(+id);
  }
}
