import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
  IsIn,
  IsInt,
  IsOptional,
  IsString,
  IsUUID,
  MaxLength,
  Min,
  MinLength,
} from 'class-validator';

export const CANALES_CAMPANA = ['SMS', 'WHATSAPP'] as const;
export type CanalCampana = (typeof CANALES_CAMPANA)[number];

export class FiltrosCampanaDto {
  @ApiProperty({ required: false })
  @IsOptional()
  @IsUUID()
  cobrador_id?: string;

  @ApiProperty({ required: false })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(0)
  min_dias_mora?: number;

  @ApiProperty({ required: false })
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(0)
  max_dias_mora?: number;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsString()
  search?: string;
}

export class CrearCampanaDto {
  @ApiProperty()
  @IsString()
  @MinLength(3)
  @MaxLength(120)
  nombre!: string;

  @ApiProperty({ enum: CANALES_CAMPANA })
  @IsIn(CANALES_CAMPANA as unknown as string[])
  canal!: CanalCampana;

  @ApiProperty({
    description:
      'Template del mensaje. Placeholders: {{nombre}}, {{saldo}}, {{documento}}, {{dias_mora}}, {{vencimiento}}',
  })
  @IsString()
  @MinLength(5)
  @MaxLength(1000)
  mensaje_template!: string;

  @ApiProperty({ type: FiltrosCampanaDto, required: false })
  @IsOptional()
  filtros?: FiltrosCampanaDto;
}
