import { ApiProperty } from '@nestjs/swagger';
import {
  IsBoolean,
  IsIn,
  IsOptional,
  IsString,
  IsUrl,
  MaxLength,
  MinLength,
} from 'class-validator';
import { EVENTOS_CARTERA } from '../webhooks/webhook-events';

export class CrearWebhookEndpointDto {
  @ApiProperty({ enum: EVENTOS_CARTERA })
  @IsIn(EVENTOS_CARTERA as unknown as string[])
  evento!: string;

  @ApiProperty()
  @IsUrl({ require_tld: false })
  @MaxLength(500)
  url!: string;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsString()
  @MinLength(16)
  @MaxLength(100)
  secreto_hmac?: string;
}

export class ActualizarWebhookEndpointDto {
  @ApiProperty({ required: false })
  @IsOptional()
  @IsUrl({ require_tld: false })
  @MaxLength(500)
  url?: string;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsBoolean()
  activo?: boolean;

  @ApiProperty({ required: false })
  @IsOptional()
  @IsString()
  @MinLength(16)
  @MaxLength(100)
  secreto_hmac?: string;
}
