namespace CashLineERP.Domain.IslamicFinance.Facilities;

public sealed class IslamicFinanceFacilityCapacity
{
    public decimal ApprovedLimitAmount { get; }
    public decimal UtilizedAmount { get; }

    public IslamicFinanceFacilityCapacity(decimal approvedLimitAmount, decimal utilizedAmount)
    {
        if (approvedLimitAmount <= 0m)
        {
            throw new InvalidOperationException("Islamic Finance facility approved limit amount must be greater than zero.");
        }

        if (utilizedAmount < 0m)
        {
            throw new InvalidOperationException("Islamic Finance facility utilized amount cannot be negative.");
        }

        if (utilizedAmount > approvedLimitAmount)
        {
            throw new InvalidOperationException("Islamic Finance facility utilized amount cannot exceed the approved limit amount.");
        }

        ApprovedLimitAmount = approvedLimitAmount;
        UtilizedAmount = utilizedAmount;
    }

    public decimal AvailableAmount => ApprovedLimitAmount - UtilizedAmount;
}
