#nullable enable
using Baya.Domain.Common;

namespace Baya.Domain.Entities.Payments;

/// <summary>
/// One leg of the append-only, double-entry financial <b>source of truth</b>. Every money event posts
/// <b>balanced</b> legs sharing a <see cref="TransactionGroupId"/> (Σ debit = Σ credit per group);
/// <see cref="AmountIrr"/> is always positive and <see cref="Direction"/> carries the sign. Per-nurse balances
/// (b13) derive by filtering <c>account_type = 'nurse_payable' AND nurse_id = …</c> — never a stored column.
/// <para>
/// This entity is <b>insert-only</b>: it implements <see cref="IEntity"/> but <b>not</b>
/// <see cref="ITimeModification"/>/<see cref="IAuditableEntity"/>, so the audit interceptor never stamps a
/// modify on it and there is no soft-delete path. Corrections are <b>new balancing rows</b>, never edits.
/// <see cref="CreatedAt"/> is set explicitly from <c>IDateTimeProvider</c> at post time.
/// </para>
/// </summary>
public class LedgerEntry : IEntity
{
    public long Id { get; set; }

    /// <summary>Groups the balanced legs of one money event.</summary>
    public Guid TransactionGroupId { get; set; }

    /// <summary>A <see cref="LedgerAccountType"/> code.</summary>
    public string AccountType { get; set; } = null!;

    /// <summary>Set for <c>nurse_payable</c>/<c>nurse_clawback_receivable</c> legs; null otherwise.</summary>
    public long? NurseId { get; set; }

    /// <summary>A <see cref="LedgerDirection"/> code — carries the sign of <see cref="AmountIrr"/>.</summary>
    public string Direction { get; set; } = null!;

    /// <summary>Always positive IRR; the sign lives in <see cref="Direction"/>. No floats.</summary>
    public long AmountIrr { get; set; }

    public long? BookingId { get; set; }

    /// <summary>A <see cref="LedgerSourceRefType"/> code.</summary>
    public string SourceRefType { get; set; } = null!;

    public long SourceRefId { get; set; }

    public string? Memo { get; set; }

    /// <summary>Append-only; never updated. Set from <c>IDateTimeProvider</c> at post time.</summary>
    public DateTime CreatedAt { get; set; }
}
