// EN: Inventory transaction entity.
// VI: Entity giao dịch tồn kho.

using InventoryService.Domain.SeedWork;

namespace InventoryService.Domain.AggregatesModel.InventoryAggregate;

/// <summary>
/// EN: Inventory transaction entity - audit trail for inventory movements.
/// VI: Entity giao dịch tồn kho - lịch sử di chuyển tồn kho.
/// </summary>
public class InventoryTransaction : Entity
{
    private Guid _inventoryItemId;
    private TransactionType _type = null!;
    private int _quantity;
    private Guid? _referenceId; // Order ID, PO ID, etc.
    private string? _notes;
    private DateTime _createdAt;

    /// <summary>
    /// EN: Inventory item ID.
    /// VI: ID inventory item.
    /// </summary>
    public Guid InventoryItemId => _inventoryItemId;

    /// <summary>
    /// EN: Transaction type.
    /// VI: Loại giao dịch.
    /// </summary>
    public TransactionType Type => _type;

    /// <summary>
    /// EN: Type ID for EF Core mapping.
    /// VI: Type ID cho EF Core mapping.
    /// </summary>
    public int TypeId { get; private set; }

    /// <summary>
    /// EN: Quantity (positive or negative).
    /// VI: Số lượng (dương hoặc âm).
    /// </summary>
    public int Quantity => _quantity;

    /// <summary>
    /// EN: Reference ID (e.g., Order ID).
    /// VI: ID tham chiếu (ví dụ: Order ID).
    /// </summary>
    public Guid? ReferenceId => _referenceId;

    /// <summary>
    /// EN: Notes for this transaction.
    /// VI: Ghi chú cho giao dịch này.
    /// </summary>
    public string? Notes => _notes;

    /// <summary>
    /// EN: Creation timestamp.
    /// VI: Thời gian tạo.
    /// </summary>
    public DateTime CreatedAt => _createdAt;

    /// <summary>
    /// EN: Private constructor for EF Core.
    /// VI: Constructor private cho EF Core.
    /// </summary>
    protected InventoryTransaction()
    {
    }

    /// <summary>
    /// EN: Create a new inventory transaction.
    /// VI: Tạo giao dịch tồn kho mới.
    /// </summary>
    public InventoryTransaction(
        Guid inventoryItemId,
        TransactionType type,
        int quantity,
        Guid? referenceId = null,
        string? notes = null)
    {
        Id = Guid.NewGuid();
        _inventoryItemId = inventoryItemId;
        _type = type;
        TypeId = type.Id;
        _quantity = quantity;
        _referenceId = referenceId;
        _notes = notes;
        _createdAt = DateTime.UtcNow;
    }
}
