import { BadRequestException, Controller, Get, Param } from '@nestjs/common';
import type { AuthUser } from '@vihar/shared';
import { TemplatesService } from './templates.service';
import { CurrentUser, RequiresCaptain } from '../../common/decorators/auth.decorators';

const ALLOWED_KEYS = new Set(['volunteer_credentials', 'whatsapp_share']);

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

  @Get(':key')
  get(@CurrentUser() user: AuthUser, @Param('key') key: string) {
    if (!user.cityId) throw new BadRequestException('No city scope');
    if (!ALLOWED_KEYS.has(key)) throw new BadRequestException('Unknown template key');
    return this.templates.getByKey(user.cityId, key);
  }
}
