using System.Text.Json.Serialization;

namespace LittleShop.DTOs;

/// <summary>
/// DTO for BTCPay Server webhook events
/// Based on BTCPay Server webhook documentation
/// </summary>
public class BTCPayWebhookDto
{
    [JsonPropertyName("deliveryId")]
    public string DeliveryId { get; set; } = string.Empty;

    [JsonPropertyName("webhookId")]
    public string WebhookId { get; set; } = string.Empty;

    [JsonPropertyName("originalDeliveryId")]
    public string? OriginalDeliveryId { get; set; }

    [JsonPropertyName("isRedelivery")]
    public bool IsRedelivery { get; set; }

    [JsonPropertyName("type")]
    public string Type { get; set; } = string.Empty;

    [JsonPropertyName("timestamp")]
    public long Timestamp { get; set; }

    [JsonPropertyName("storeId")]
    public string StoreId { get; set; } = string.Empty;

    [JsonPropertyName("invoiceId")]
    public string InvoiceId { get; set; } = string.Empty;

    [JsonPropertyName("afterExpiration")]
    public bool? AfterExpiration { get; set; }

    [JsonPropertyName("manuallyMarked")]
    public bool? ManuallyMarked { get; set; }

    [JsonPropertyName("overPaid")]
    public bool? OverPaid { get; set; }

    [JsonPropertyName("partiallyPaid")]
    public bool? PartiallyPaid { get; set; }

    [JsonPropertyName("payment")]
    public BTCPayWebhookPayment? Payment { get; set; }
}

public class BTCPayWebhookPayment
{
    [JsonPropertyName("id")]
    public string Id { get; set; } = string.Empty;

    [JsonPropertyName("receivedDate")]
    public long ReceivedDate { get; set; }

    [JsonPropertyName("value")]
    public decimal Value { get; set; }

    [JsonPropertyName("fee")]
    public decimal? Fee { get; set; }

    [JsonPropertyName("status")]
    public string Status { get; set; } = string.Empty;

    [JsonPropertyName("destination")]
    public string? Destination { get; set; }

    [JsonPropertyName("paymentMethod")]
    public string PaymentMethod { get; set; } = string.Empty;

    [JsonPropertyName("paymentMethodPaid")]
    public decimal PaymentMethodPaid { get; set; }

    [JsonPropertyName("transactionData")]
    public BTCPayWebhookTransactionData? TransactionData { get; set; }
}

public class BTCPayWebhookTransactionData
{
    [JsonPropertyName("transactionHash")]
    public string? TransactionHash { get; set; }

    [JsonPropertyName("blockHash")]
    public string? BlockHash { get; set; }

    [JsonPropertyName("blockHeight")]
    public int? BlockHeight { get; set; }

    [JsonPropertyName("confirmations")]
    public int? Confirmations { get; set; }
}