import { Controller, Get, Post, Body, Put, Param, Query } from '@nestjs/common';
import { EmailTemplatesService } from './email_templates.service';
import { EmailTemplate } from './email_templates.entity';
import { Public } from '../auth/public.decorator';

@Controller('admin/email-templates')
export class EmailTemplatesController {
  constructor(private readonly emailTemplatesService: EmailTemplatesService) {}

  @Public()
  @Get()
  async findAll(
    @Query('page') page: string = '1',
    @Query('limit') limit: string = '10',
  ): Promise<any> {
    const pageNumber = parseInt(page, 10);
    const limitNumber = parseInt(limit, 10);
    return this.emailTemplatesService.findAllPaginated(pageNumber, limitNumber);
  }

  @Public()
  @Get(':id')
  async findOne(@Param('id') id: string): Promise<EmailTemplate> {
    return this.emailTemplatesService.findOne(id);
  }

  @Public()
  @Post()
  async create(@Body() data: Partial<EmailTemplate>): Promise<EmailTemplate> {
    return this.emailTemplatesService.create(data);
  }

  @Public()
  @Put(':id')
  async update(
    @Param('id') id: string,
    @Body() data: Partial<EmailTemplate>,
  ): Promise<EmailTemplate> {
    return this.emailTemplatesService.update(id, data);
  }
}
