import { ApiProperty } from '@nestjs/swagger';
import { ArrayMaxSize, ArrayMinSize, ArrayNotEmpty, IsArray, IsInt } from 'class-validator';

export enum PaymentLinkSendStatusEnum {
  SENT = 'sent',
  SKIPPED = 'skipped',
  FAILED = 'failed',
}

export class SendPaymentLinksDto {
  @ApiProperty({
    description:
      'Registration IDs to send the payment link communication to. Only registrations that are not cancelled/archived/deleted and whose payment status is null or online_pending are processed; the rest are reported as skipped.',
    type: [Number],
    example: [101, 102, 103],
  })
  @IsArray({ message: 'registrationIds must be an array' })
  @ArrayNotEmpty({ message: 'registrationIds must not be empty' })
  @IsInt({ each: true, message: 'Each registrationId must be an integer' })
  @ArrayMaxSize(10, { message: 'registrationIds must not contain more than 10 items' })
  @ArrayMinSize(1, { message: 'registrationIds must contain at least 1 item' })
  registrationIds: number[];
}

export class PaymentLinkSendResultDto {
  @ApiProperty({ example: 101 })
  registrationId: number;

  @ApiProperty({ enum: PaymentLinkSendStatusEnum, example: PaymentLinkSendStatusEnum.SENT })
  status: PaymentLinkSendStatusEnum;

  @ApiProperty({
    required: false,
    description: 'Reason the registration was skipped or failed',
    example: 'Payment status is not null or online_pending',
  })
  reason?: string;
}

export class BulkPaymentLinkResultDto {
  @ApiProperty({ description: 'Total registration IDs received (after de-duplication)', example: 3 })
  total: number;

  @ApiProperty({ description: 'Count of registrations the communication was sent to', example: 2 })
  sent: number;

  @ApiProperty({ description: 'Count of ineligible registrations that were skipped', example: 1 })
  skipped: number;

  @ApiProperty({ description: 'Count of eligible registrations whose send failed', example: 0 })
  failed: number;

  @ApiProperty({ type: [PaymentLinkSendResultDto] })
  results: PaymentLinkSendResultDto[];
}
