import { ApiProperty } from "@nestjs/swagger";

export class WebhookEndpointDto {
  @ApiProperty({ example: "whe_01HXYZABCDEFGHJKMNPQRSTV" })
  id!: string;

  @ApiProperty({ example: "mer_01HXYZABCDEFGHJKMNPQRSTV" })
  merchantId!: string;

  @ApiProperty({ example: "https://merchant.com/webhooks/payments" })
  url!: string;

  @ApiProperty({
    type: [String],
    example: ["payment_intent.succeeded", "payment_intent.failed"],
  })
  subscribedEvents!: string[];

  @ApiProperty({ example: true })
  active!: boolean;

  @ApiProperty({ required: false, nullable: true, example: "Producción" })
  description!: string | null;

  @ApiProperty({ example: "2026-06-07T14:30:00.000Z" })
  createdAt!: Date;

  @ApiProperty({ example: "2026-06-07T14:30:00.000Z" })
  updatedAt!: Date;
}

export class CreatedWebhookEndpointDto extends WebhookEndpointDto {
  @ApiProperty({
    example: "whsec_5f3a9b2c1d8e7f4a3b2c1d8e7f4a3b2c1d8e7f4a3b2c1d8e7f4a3b2c1d8e7f4a",
    description:
      "Secret HMAC para verificar firmas de webhooks. Se devuelve **una sola vez**. " +
      "Usalo del lado del merchant para validar el header `X-Payments-Signature` (formato Stripe: `t=...,v1=...`).",
  })
  secret!: string;
}

export class WebhookEndpointListDto {
  @ApiProperty({ type: [WebhookEndpointDto] })
  data!: WebhookEndpointDto[];

  @ApiProperty({ required: false, nullable: true, example: null })
  nextCursor!: string | null;
}
