import {
  Controller,
  Get,
  Post,
  Put,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  UseGuards,
} from '@nestjs/common';
import { SeoTemplatesService } from './seo_templates.service';
import { Public } from '../auth/public.decorator';

@Controller('seo-templates')
export class SeoTemplatesController {
  constructor(private readonly seoTemplatesService: SeoTemplatesService) {}

  /**
   * For the "Save/Upsert" logic in the new SEO Default dashboard tab
   * Priority: Top (prevents :id routes from catching the 'upsert' keyword)
   */
  @Public()
  @Post('upsert/:key')
  upsert(@Param('key') key: string, @Body() body: any) {
    return this.seoTemplatesService.upsert(key, body);
  }

  @Public()
  @Delete('key/:key')
  removeByKey(@Param('key') key: string) {
    return this.seoTemplatesService.removeByKey(key);
  }

  @Public()
  @Put('upsert/:key')
  upsertPut(@Param('key') key: string, @Body() body: any) {
    return this.seoTemplatesService.upsert(key, body);
  }

  @Public()
  @Post()
  create(@Body() createDto: any) {
    return this.seoTemplatesService.create(createDto);
  }

  @Public()
  @Get()
  findAll() {
    return this.seoTemplatesService.findAll();
  }

  /**
   * Special high-performance endpoint for the frontend resolvers
   */
  @Public()
  @Get('key/:key')
  findByKey(@Param('key') key: string) {
    return this.seoTemplatesService.findByKey(key);
  }

  @Public()
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.seoTemplatesService.findOne(+id);
  }

  @Public()
  @Patch(':id')
  update(@Param('id') id: string, @Body() updateDto: any) {
    return this.seoTemplatesService.update(+id, updateDto);
  }

  @Public()
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.seoTemplatesService.remove(+id);
  }
}
