package cloud.nstart.terravault.ordinis.restapi.dto.webhook;

import cloud.nstart.terravault.ordinis.domain.webhook.WebhookDelivery;

import java.time.OffsetDateTime;
import java.util.UUID;

/** Response для delivery history listing (drilldown в admin UI). */
public record WebhookDeliveryResponse(
    Long id,
    UUID subscriptionId,
    Long outboxEventId,
    WebhookDelivery.Status status,
    int attemptCount,
    OffsetDateTime createdAt,
    OffsetDateTime nextAttemptAt,
    OffsetDateTime lastAttemptAt,
    OffsetDateTime deliveredAt,
    String lastError,
    Integer lastStatusCode,
    OffsetDateTime dlqAt) {

  public static WebhookDeliveryResponse from(WebhookDelivery d) {
    return new WebhookDeliveryResponse(
        d.getId(),
        d.getSubscriptionId(),
        d.getOutboxEventId(),
        d.getStatus(),
        d.getAttemptCount(),
        d.getCreatedAt(),
        d.getNextAttemptAt(),
        d.getLastAttemptAt(),
        d.getDeliveredAt(),
        d.getLastError(),
        d.getLastStatusCode(),
        d.getDlqAt());
  }
}
