using CashLineERP.SharedKernel.IslamicFinance;

namespace CashLineERP.Domain.IslamicFinance.ProductProfiles;

public sealed class IslamicFinanceProductFundingProfile
{
    public bool AllowsPartnerFunding { get; }
    public bool AllowsCashLineFunding { get; }

    public IslamicFinanceProductFundingProfile(
        bool allowsPartnerFunding,
        bool allowsCashLineFunding)
    {
        if (!allowsPartnerFunding && !allowsCashLineFunding)
        {
            throw new InvalidOperationException("Islamic Finance product profile must allow at least one funding path.");
        }

        AllowsPartnerFunding = allowsPartnerFunding;
        AllowsCashLineFunding = allowsCashLineFunding;
    }

    public bool AllowsHybridFunding => AllowsPartnerFunding && AllowsCashLineFunding;

    public bool SupportsMode(IslamicFinanceFundingSourceMode fundingSourceMode) => fundingSourceMode switch
    {
        IslamicFinanceFundingSourceMode.Partner => AllowsPartnerFunding,
        IslamicFinanceFundingSourceMode.CashLine => AllowsCashLineFunding,
        IslamicFinanceFundingSourceMode.Hybrid => AllowsHybridFunding,
        _ => false
    };
}
