import { ApiProperty } from "@nestjs/swagger";
import { ArrayMinSize, ArrayUnique, IsArray, IsOptional, IsString, IsUrl, Length } from "class-validator";

export class CreateWebhookEndpointDto {
  @ApiProperty({
    example: "https://merchant.com/webhooks/payments",
    description: "URL HTTPS donde se entregarán los eventos. En producción se exige `https`.",
  })
  @IsUrl({ require_protocol: true, require_tld: false, protocols: ["http", "https"] })
  url!: string;

  @ApiProperty({
    type: [String],
    example: ["payment_intent.succeeded", "payment_intent.failed", "checkout_session.expired"],
    description:
      "Lista de eventos a los que se suscribe. Usar `*` para recibir todos. Ver catálogo en `/docs · Webhooks`.",
  })
  @IsArray()
  @ArrayMinSize(1)
  @ArrayUnique()
  @IsString({ each: true })
  subscribedEvents!: string[];

  @ApiProperty({ required: false, example: "Producción · servidor de pedidos" })
  @IsOptional()
  @IsString()
  @Length(1, 200)
  description?: string;
}
