/**
 * Queue Bulk WhatsApp DTO
 *
 * Input to WhatsAppQueueService.queueBulkWhatsApp — one logical batch of WhatsApp recipients
 * that share a WATI template + broadcast. The queue service chunks the recipients into one bulk
 * message per QUEUE_CONSTANTS.BULK_WHATSAPP_BATCH_SIZE; the processor sends each chunk via
 * CommunicationService.sendBulkTemplateMessage (WATI bulk template send).
 */

import { IsArray, IsInt, IsObject, IsOptional, IsString, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';

class BulkWhatsAppQueueParameter {
  @IsString()
  name: string;

  @IsString()
  value: string;
}

class BulkWhatsAppQueueRecipient {
  @IsString()
  whatsappNumber: string;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => BulkWhatsAppQueueParameter)
  @IsOptional()
  customParams?: BulkWhatsAppQueueParameter[];

  @IsInt()
  @IsOptional()
  registrationId?: number;
}

export class QueueBulkWhatsAppDto {
  @IsString()
  templateName: string;

  @IsString()
  broadcastName: string;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => BulkWhatsAppQueueRecipient)
  recipients: BulkWhatsAppQueueRecipient[];

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => BulkWhatsAppQueueParameter)
  @IsOptional()
  globalParameters?: BulkWhatsAppQueueParameter[];

  /** hdb_communication_templates id recorded on each tracking row. */
  @IsInt()
  @IsOptional()
  templateId?: number | null;

  @IsInt()
  @IsOptional()
  createdBy?: number;

  @IsString()
  @IsOptional()
  correlationId?: string;

  @IsString()
  @IsOptional()
  userId?: string;

  @IsObject()
  @IsOptional()
  metadata?: Record<string, any>;
}
