import { Controller, Get, Query, Req, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import {
  TreatmentCatalogContext,
  TreatmentCatalogService,
} from './treatment-catalog.service';

@ApiTags('treatment-catalog')
@ApiBearerAuth('JWT-auth')
@UseGuards(JwtAuthGuard)
@Controller('treatment-catalog')
export class TreatmentCatalogController {
  constructor(private readonly treatmentCatalogService: TreatmentCatalogService) {}

  @Get()
  @ApiOperation({ summary: 'List active treatment types with localized labels' })
  @ApiQuery({
    name: 'context',
    required: false,
    enum: ['appointment', 'treatment'],
    description: 'Filter to types selectable in the given context',
  })
  async list(
    @Req() req: { user?: { language?: string | null } },
    @Query('context') context?: string,
  ) {
    const normalizedContext =
      context === 'appointment' || context === 'treatment'
        ? (context as TreatmentCatalogContext)
        : undefined;
    const data = await this.treatmentCatalogService.list(
      req.user?.language,
      normalizedContext,
    );
    return { success: true, data };
  }
}
