import { Controller, Get, UseGuards } from '@nestjs/common';
import {
  ApiBearerAuth,
  ApiExtraModels,
  ApiOkResponse,
  ApiOperation,
  ApiTags,
} from '@nestjs/swagger';
import { CurrentFamilyActor } from '../../auth/current-family-actor.decorator.js';
import { FamilyAccessTokenGuard } from '../../auth/family-access/family-access.guard.js';
import type { FamilyActorContext } from '../../common/family-actor-context.js';
import { CPatientMeResponseDto } from '../dto/c-patient-me-response.dto.js';
import {
  CPatientLifecycleResponseDto,
  PATIENT_LIFECYCLE_SWAGGER_MODELS,
} from '../dto/patient-lifecycle-response.dto.js';
import { CPatientsService } from './c-patients.service.js';

/**
 * C 端患者控制器：患者本人按登录手机号查询自己的档案与生命周期。
 */
@ApiTags('患者管理(C端)')
@ApiBearerAuth('bearer')
@Controller('c/patients')
@UseGuards(FamilyAccessTokenGuard)
export class CPatientsController {
  constructor(private readonly patientsService: CPatientsService) {}

  /**
   * 读取当前登录患者的基础信息。
   */
  @Get('me')
  @ApiOperation({ summary: '获取当前登录患者信息' })
  @ApiOkResponse({
    description: '返回当前 C 端登录账号绑定的患者档案与账号信息',
    type: CPatientMeResponseDto,
  })
  me(@CurrentFamilyActor() actor: FamilyActorContext) {
    return this.patientsService.getMeByAccount(actor.id);
  }

  /**
   * 根据当前登录手机号查询单患者生命周期。
   */
  @Get('my-lifecycle')
  @ApiOperation({ summary: '按当前登录手机号查询患者生命周期' })
  @ApiExtraModels(...PATIENT_LIFECYCLE_SWAGGER_MODELS)
  @ApiOkResponse({
    description: '按当前登录手机号返回唯一患者的生命周期数据',
    type: CPatientLifecycleResponseDto,
  })
  getMyLifecycle(@CurrentFamilyActor() actor: FamilyActorContext) {
    return this.patientsService.getFamilyLifecycleByAccount(actor.id);
  }
}
