using PowderCoating.Core.Enums;

namespace PowderCoating.Application.DTOs.Invoice;

// ── Refund DTOs ───────────────────────────────────────────────────────────────

public class RefundDto
{
    public int Id { get; set; }
    public int InvoiceId { get; set; }
    public int? PaymentId { get; set; }
    public decimal Amount { get; set; }
    public DateTime RefundDate { get; set; }
    public PaymentMethod RefundMethod { get; set; }
    public string RefundMethodDisplay => RefundMethod switch
    {
        PaymentMethod.Cash => "Cash",
        PaymentMethod.Check => "Check",
        PaymentMethod.CreditDebitCard => "Credit/Debit Card",
        PaymentMethod.BankTransferACH => "Bank Transfer / ACH",
        PaymentMethod.DigitalPayment => "Digital Payment",
        PaymentMethod.StoreCredit => "Store Credit",
        _ => RefundMethod.ToString()
    };
    public string Reason { get; set; } = string.Empty;
    public string? Reference { get; set; }
    public string? Notes { get; set; }
    public RefundStatus Status { get; set; }
    public DateTime? IssuedDate { get; set; }
    public string? IssuedByName { get; set; }
}

public class IssueRefundDto
{
    public int? PaymentId { get; set; }
    public decimal Amount { get; set; }
    public DateTime RefundDate { get; set; } = DateTime.Today;
    public PaymentMethod RefundMethod { get; set; }
    /// <summary>Bank/cash account money leaves when issuing a cash/card refund. Null for store credit.</summary>
    public int? DepositAccountId { get; set; }
    public string Reason { get; set; } = string.Empty;
    public string? Reference { get; set; }
    public string? Notes { get; set; }
}

// ── Credit Memo DTOs ──────────────────────────────────────────────────────────

public class CreditMemoDto
{
    public int Id { get; set; }
    public string MemoNumber { get; set; } = string.Empty;
    public int CustomerId { get; set; }
    public string CustomerName { get; set; } = string.Empty;
    public int? OriginalInvoiceId { get; set; }
    public string? OriginalInvoiceNumber { get; set; }
    public int? ReworkRecordId { get; set; }
    public decimal Amount { get; set; }
    public decimal AmountApplied { get; set; }
    public decimal RemainingBalance { get; set; }
    public DateTime IssueDate { get; set; }
    public DateTime? ExpiryDate { get; set; }
    public string Reason { get; set; } = string.Empty;
    public string? Notes { get; set; }
    public CreditMemoStatus Status { get; set; }
    public string? IssuedByName { get; set; }
    public List<CreditMemoApplicationDto> Applications { get; set; } = new();
}

public class CreditMemoApplicationDto
{
    public int Id { get; set; }
    public int CreditMemoId { get; set; }
    public string MemoNumber { get; set; } = string.Empty;
    public int InvoiceId { get; set; }
    public string InvoiceNumber { get; set; } = string.Empty;
    public decimal AmountApplied { get; set; }
    public DateTime AppliedDate { get; set; }
    public string? AppliedByName { get; set; }
}

public class IssueCreditMemoDto
{
    public decimal Amount { get; set; }
    public string Reason { get; set; } = string.Empty;
    public string? Notes { get; set; }
    public DateTime? ExpiryDate { get; set; }
    public int? ReworkRecordId { get; set; }
}

public class ApplyCreditDto
{
    public int CreditMemoId { get; set; }
    public decimal Amount { get; set; }
}
