import { Body, Controller, Get, Post, Patch, Delete, Param, Query, UseGuards } from '@nestjs/common';
import { TemplatesService } from './templates.service';
import { JwtAuthGuard } from '../../common/guards/jwt.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { Workspace } from '../../common/decorators/workspace.decorator';

@Controller('templates')
@UseGuards(JwtAuthGuard)
export class TemplatesController {
  constructor(private readonly templatesService: TemplatesService) {}

  @Get()
  async list(
    @Workspace('id') wsId: string,
    @Query() query: { category?: string; type?: string },
  ) {
    return this.templatesService.list(wsId, query);
  }

  @Get(':id')
  async getById(@Param('id') id: string, @Workspace('id') wsId: string) {
    return this.templatesService.findById(id, wsId);
  }

  @Post()
  async create(
    @Workspace('id') wsId: string,
    @CurrentUser('userId') userId: string,
    @Body() dto: any,
  ) {
    return this.templatesService.create(wsId, userId, dto);
  }

  @Patch(':id')
  async update(
    @Param('id') id: string,
    @Workspace('id') wsId: string,
    @CurrentUser('userId') userId: string,
    @Body() dto: any,
  ) {
    return this.templatesService.update(id, wsId, userId, dto);
  }

  @Delete(':id')
  async delete(@Param('id') id: string, @Workspace('id') wsId: string) {
    return this.templatesService.delete(id, wsId);
  }
}