import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { GeneratedLinkSourceType } from 'src/common/enum/generated-link-source-type.enum';
import { OnlineSessionRegistrationStatus } from 'src/common/enum/online-session-registration-status.enum';

/** One row of `zoom_generated_registrant_link`, shaped for the API response. */
export class GeneratedZoomLinkV1 {
  @ApiProperty()
  id: number;

  @ApiProperty({ description: 'Which session this link was registered against.' })
  programSessionId: number;

  @ApiProperty({ enum: GeneratedLinkSourceType })
  sourceType: GeneratedLinkSourceType;

  @ApiPropertyOptional({ description: 'Real user id — ROLE rows only.' })
  userId?: number | null;

  @ApiPropertyOptional({ description: "Matched role key for ROLE rows; 'SYSTEM' for PLACEHOLDER rows." })
  roleKey?: string | null;

  @ApiPropertyOptional({ description: 'Batch label — PLACEHOLDER rows only.' })
  batchName?: string | null;

  @ApiPropertyOptional({ description: '1..count within the batch — PLACEHOLDER rows only.' })
  sequenceNumber?: number | null;

  @ApiProperty()
  displayName: string;

  @ApiProperty({
    description:
      'The recipient\'s real email — ROLE rows show the matched user\'s own address, ' +
      'PLACEHOLDER rows show their generated slot address. Never the uniquely-tagged variant ' +
      'actually sent to Zoom.',
  })
  email: string;

  @ApiPropertyOptional({ description: "Real user's phone number on file — ROLE rows only." })
  sourceMobile?: string | null;

  @ApiPropertyOptional()
  joinUrl?: string | null;

  @ApiProperty({ enum: OnlineSessionRegistrationStatus })
  status: OnlineSessionRegistrationStatus;

  @ApiPropertyOptional()
  failureReason?: string | null;
}

export class GenerateZoomGeneralLinksResultV1 {
  @ApiProperty({ type: [GeneratedZoomLinkV1] })
  created: GeneratedZoomLinkV1[];

  @ApiProperty({ description: 'Count of requested recipients that already had an active row for this session — skipped, no Zoom call made.' })
  skippedExisting: number;

  @ApiProperty({
    description: 'Recipients whose Zoom registration attempt failed this run — recorded in the table with status=failed.',
    type: 'array',
    items: {
      type: 'object',
      properties: {
        name: { type: 'string' },
        email: { type: 'string' },
        reason: { type: 'string' },
      },
    },
  })
  failed: { name: string; email: string; reason: string }[];
}
