import {
  Controller,
  Get,
  Post,
  Body,
  Put,
  Param,
  Delete,
  UseGuards,
  Req,
} from '@nestjs/common';
import { TemplateService } from '../services/template.service';
import { CreateTemplateDto } from '../dto/create-template.dto';
import { UpdateTemplateDto } from '../dto/update-template.dto';
import { CombinedAuthGuard } from '../../auth/combined-auth.guard';

@Controller('assessment/templates')
@UseGuards(CombinedAuthGuard)
export class TemplateController {
  constructor(private readonly templateService: TemplateService) {}

  @Post()
  create(@Body() createDto: CreateTemplateDto, @Req() req: any) {
    return this.templateService.create(
      createDto,
      req.user.id,
      req.user.tenantId,
    );
  }

  @Get()
  findAll(@Req() req: any) {
    return this.templateService.findAll(req.user.tenantId);
  }

  @Get(':id')
  async findOne(@Param('id') id: string, @Req() req: any) {
    return this.templateService.findOne(id, req.user.id, req.user.tenantId);
  }

  @Put(':id')
  async update(
    @Param('id') id: string,
    @Body() updateDto: UpdateTemplateDto,
    @Req() req: any,
  ) {
    return this.templateService.update(
      id,
      updateDto,
      req.user.id,
      req.user.tenantId,
    );
  }

  @Delete(':id')
  async remove(@Param('id') id: string, @Req() req: any) {
    return this.templateService.remove(id, req.user.id, req.user.tenantId);
  }
}
