using ERPCore.Domain.Enums;

namespace ERPCore.Domain.Entities;

public class SalesInvoice
{
    public int SalesInvoiceId { get; set; }
    public string InvoiceNo { get; set; } = string.Empty;
    public DateTime InvoiceDate { get; set; }

    public int CustomerId { get; set; }
    public Customer? Customer { get; set; }

    public string CustomerSnapshotName { get; set; } = string.Empty;
    public string? CustomerSnapshotTaxNo { get; set; }

    public int WarehouseId { get; set; }
    public Warehouse? Warehouse { get; set; }

    public SalesInvoiceType InvoiceType { get; set; } = SalesInvoiceType.B2C;
    public SalesInvoiceStatus Status { get; set; } = SalesInvoiceStatus.Draft;

    public decimal Subtotal { get; set; }
    public decimal DiscountTotal { get; set; }
    public decimal TaxTotal { get; set; }
    public decimal GrandTotal { get; set; }
    public decimal RoundOff { get; set; }
    public decimal NetPayable { get; set; }
    public decimal PaidAmount { get; set; }
    public decimal BalanceAmount { get; set; }

    /// <summary>Journal number of the revenue-recognition GL journal entry posted when this
    /// invoice is Posted (Debit Accounts Receivable / Credit Sales Revenue + Tax, plus COGS —
    /// see SalesPostingService.PostInvoiceAsync). Unlike a SalesSlip, an invoice posts its own
    /// GL entry immediately rather than waiting for Sales Day End, since invoices aren't a
    /// cashier document and don't go through that close-out.</summary>
    public string? GlJournalNo { get; set; }
    public DateTime? GlPostedAt { get; set; }

    public int CreatedBy { get; set; }
    public User? Creator { get; set; }

    public DateTime CreatedAt { get; set; }
    public DateTime? UpdatedAt { get; set; }

    public uint RowVersion { get; set; }

    public ICollection<SalesInvoiceLine> Lines { get; set; } = new List<SalesInvoiceLine>();
    public ICollection<SalesInvoicePayment> Payments { get; set; } = new List<SalesInvoicePayment>();
}
