import { Controller, Get, Param } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { ZodResponse } from 'nestjs-zod';
import { Permission } from '@pac/types';
import { RequirePermission } from '../../common/decorators/permissions.decorator';
import {
  TenantScope,
  TenantScopeContext,
} from '../../common/decorators/tenant-scope.decorator';
import { PersonaResponseDto } from './dto/persona.dto';
import { PersonaService } from './persona.service';

@ApiTags('persona')
@ApiBearerAuth('accessToken')
@Controller('patients/:patientId/persona')
export class PersonaController {
  constructor(private readonly persona: PersonaService) {}

  @Get()
  @ZodResponse({ status: 200, type: PersonaResponseDto })
  @RequirePermission(Permission.PERSONA_VIEW)
  @ApiOperation({ summary: 'Current (non-superseded) persona for the patient' })
  async getCurrent(
    @TenantScope() _scope: TenantScopeContext,
    @Param('patientId') patientId: string,
  ) {
    const persona = await this.persona.getCurrent(patientId);
    return { persona };
  }
}
