import { ApiProperty } from "@nestjs/swagger";
import { Provider, WebhookEventOutStatus } from "@prisma/client";

export class EventOutDto {
  @ApiProperty({ example: "evt_01HXYZABCDEFGHJKMNPQRSTV" })
  id!: string;

  @ApiProperty({ example: "whe_01HXYZABCDEFGHJKMNPQRSTV" })
  endpointId!: string;

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

  @ApiProperty({ example: "payment_intent.succeeded" })
  eventType!: string;

  @ApiProperty({ enum: WebhookEventOutStatus, example: WebhookEventOutStatus.delivered })
  status!: WebhookEventOutStatus;

  @ApiProperty({ example: 1 })
  attempts!: number;

  @ApiProperty({ required: false, nullable: true, example: "2026-06-07T14:30:00.000Z" })
  lastAttemptAt!: Date | null;

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

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

  @ApiProperty({ required: false, nullable: true, example: "2026-06-07T14:30:00.000Z" })
  deliveredAt!: Date | null;

  @ApiProperty({ description: "Payload firmado enviado al endpoint." })
  payload!: Record<string, unknown>;

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

export class EventOutListDto {
  @ApiProperty({ type: [EventOutDto] })
  data!: EventOutDto[];

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

export class EventInDto {
  @ApiProperty({ example: "wei_01HXYZABCDEFGHJKMNPQRSTV" })
  id!: string;

  @ApiProperty({ enum: Provider, example: Provider.dlocal })
  provider!: Provider;

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

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

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

  @ApiProperty({ required: false, nullable: true })
  processedAt!: Date | null;

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

  @ApiProperty()
  payload!: Record<string, unknown>;

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

export class EventInListDto {
  @ApiProperty({ type: [EventInDto] })
  data!: EventInDto[];

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