using ERPCore.Domain.Enums;

namespace ERPCore.Domain.Entities;

/// <summary>
/// Stock adjustment header (FR-STK-07) — the highest-risk feature in the phase
/// (02-SECURITY C.5). Auto-posts in Phase 1 with a mandatory reason code and user
/// stamp. Mutable aggregate with an <see cref="RowVersion"/> token (docs/10 C.10).
/// Model: docs/10 Part C.6.
/// </summary>
public class StockAdjustment
{
    public int AdjustmentId { get; set; }
    public string DocNo { get; set; } = string.Empty;

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

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

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

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

    public DateTime CreatedAt { get; set; }
    public uint RowVersion { get; set; }

    /// <summary>Journal number of the real GL journal entry posted for this adjustment (set on create — it
    /// auto-posts). Increases and decreases post separately (never netted) so gains/losses stay visible.</summary>
    public string? GlJournalNo { get; set; }
    public DateTime? GlPostedAt { get; set; }

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