using ERPCore.Domain.Enums;

namespace ERPCore.Domain.Entities;

/// <summary>
/// Sales return header — a customer returns previously sold goods, generating an
/// inbound stock movement. Auto-posts with a mandatory reason code, mirroring
/// <see cref="PurchaseReturn"/> with the direction reversed.
/// </summary>
public class SalesReturn
{
    public int ReturnId { get; set; }
    public string DocNo { get; set; } = string.Empty;

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

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

    public int ReasonCodeId { get; set; }
    public ReasonCode? ReasonCode { get; set; }

    public ReturnStatus Status { get; set; } = ReturnStatus.Posted;

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

    public DateTime CreatedAt { get; set; }

    /// <summary>Journal number of the real GL journal entry posted for this return (set on create — it auto-posts).
    /// Reverses Inventory/COGS only — <see cref="SalesReturnLine"/> carries no unit price, so revenue/tax aren't
    /// reversed here (they'd need a per-line price this document doesn't capture).</summary>
    public string? GlJournalNo { get; set; }
    public DateTime? GlPostedAt { get; set; }

    public ICollection<SalesReturnLine> Lines { get; set; } = new List<SalesReturnLine>();
}
