import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Param,
  Body,
  Query,
  Patch,
} from '@nestjs/common';
import { PerksService } from './perks.service';
import { Public } from '../auth/public.decorator';
import {
  ApiBearerAuth,
  ApiTags,
  ApiOperation,
  ApiBody,
  ApiParam,
  ApiQuery,
} from '@nestjs/swagger';

@ApiTags('perks')
@ApiBearerAuth('access-token')
@Controller('perks')
export class PerksController {
  constructor(private readonly perksService: PerksService) {}

  @Public()
  @Get()
  @ApiOperation({ summary: 'Get all perks' })
  findAll() {
    return this.perksService.findAll();
  }

  @Public()
  @Get('filtered')
  @ApiOperation({ summary: 'Get all perks paginated' })
  @ApiQuery({ name: 'page', required: false, type: Number })
  @ApiQuery({ name: 'limit', required: false, type: Number })
  findAllPaginated(
    @Query('page') page: number = 1,
    @Query('limit') limit: number = 10,
  ) {
    return this.perksService.findAllPaginated(
      Number(page || 1),
      Number(limit || 10),
    );
  }

  @Public()
  @Get(':id')
  @ApiOperation({ summary: 'Get perk by id' })
  @ApiParam({ name: 'id', type: Number })
  findOne(@Param('id') id: number) {
    return this.perksService.findOne(id);
  }

  @Public()
  @Post()
  @ApiOperation({ summary: 'Create perk' })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { name: { type: 'string' }, icon: { type: 'string' } },
      required: ['name'],
    },
  })
  create(@Body() body: any) {
    return this.perksService.create(body);
  }

  @Public()
  @Put(':id')
  @ApiOperation({ summary: 'Update perk' })
  @ApiParam({ name: 'id', type: Number })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { name: { type: 'string' }, icon: { type: 'string' } },
    },
  })
  update(@Param('id') id: number, @Body() body: any) {
    return this.perksService.update(id, body);
  }

  @Public()
  @Patch(':id')
  @ApiOperation({ summary: 'Patch perk' })
  @ApiParam({ name: 'id', type: Number })
  @ApiBody({
    schema: {
      type: 'object',
      properties: { name: { type: 'string' }, icon: { type: 'string' } },
    },
  })
  patch(@Param('id') id: number, @Body() body: any) {
    return this.perksService.update(id, body);
  }

  @Public()
  @Delete(':id')
  @ApiOperation({ summary: 'Delete perk' })
  @ApiParam({ name: 'id', type: Number })
  remove(@Param('id') id: number) {
    return this.perksService.remove(id);
  }
}
