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

@ApiTags('organizationTypes')
@ApiBearerAuth('access-token')
@Controller('organizationTypes')
export class OrganizationTypesController {
  constructor(
    private readonly organizationTypesService: OrganizationTypesService,
  ) {}

  @Public()
  @Get('filtered')
  @ApiOperation({ summary: 'Get all organization types 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.organizationTypesService.findAllPaginated(
      Number(page || 1),
      Number(limit || 10),
    );
  }

  @Public()
  @Post()
  @ApiOperation({ summary: 'Create organization type' })
  @ApiBody({ type: Object })
  create(@Body() body: any) {
    return this.organizationTypesService.create(body);
  }

  @Public()
  @Put(':id')
  @ApiOperation({ summary: 'Update organization type' })
  @ApiParam({ name: 'id', type: Number })
  @ApiBody({ type: Object })
  update(@Param('id') id: string, @Body() body: any) {
    return this.organizationTypesService.update(+id, body);
  }

  @Public()
  @Patch(':id')
  @ApiOperation({ summary: 'Patch organization type' })
  @ApiParam({ name: 'id', type: Number })
  @ApiBody({ type: Object })
  patch(@Param('id') id: string, @Body() body: any) {
    return this.organizationTypesService.update(+id, body);
  }

  @Public()
  @Delete(':id')
  @ApiOperation({ summary: 'Delete organization type' })
  @ApiParam({ name: 'id', type: Number })
  remove(@Param('id') id: string) {
    return this.organizationTypesService.remove(+id);
  }
}
