using System.ComponentModel.DataAnnotations.Schema;

namespace CashLineERP.Domain.IslamicFinance.Disbursements;

public sealed class IslamicFinanceMurabahaDisbursementAmount
{
    public decimal InstructedAmount { get; }
    public decimal ExecutedAmount { get; }

    [NotMapped]
    public decimal OutstandingAmount => Math.Max(0m, InstructedAmount - ExecutedAmount);

    public IslamicFinanceMurabahaDisbursementAmount(decimal instructedAmount, decimal executedAmount)
    {
        if (instructedAmount <= 0m)
        {
            throw new InvalidOperationException("Islamic Finance Murabaha disbursement instructed amount must be positive.");
        }

        if (executedAmount < 0m)
        {
            throw new InvalidOperationException("Islamic Finance Murabaha disbursement executed amount cannot be negative.");
        }

        if (executedAmount > instructedAmount)
        {
            throw new InvalidOperationException("Islamic Finance Murabaha disbursement executed amount cannot exceed instructed amount.");
        }

        InstructedAmount = instructedAmount;
        ExecutedAmount = executedAmount;
    }
}
