using CashLineERP.Domain.Common;

namespace CashLineERP.Domain.Parties;

public sealed class BusinessParty : Entity
{
    public long Id { get; private set; }

    public string PartyCode { get; private set; } = string.Empty;

    public string PartyName { get; private set; } = string.Empty;

    public string PartyType { get; private set; } = string.Empty;

    public string CountryCode { get; private set; } = "EG";

    // Egypt: الرقم القومي للمنشأة (optional for MVP, globally unique when provided)
    public string? FirmNationalId { get; private set; }

    public string? TaxRegistrationNumber { get; private set; }

    public string? TaxBranchCode { get; private set; }

    public string? Email { get; private set; }

    public string? MobileNumber { get; private set; }

    public string? AddressLine1 { get; private set; }

    public decimal? CreditLimitAmount { get; private set; }

    public int? CreditTermsDays { get; private set; }

    public bool IsCreditHoldEnabled { get; private set; }

    public string? CreditHoldReason { get; private set; }

    public bool IsActive { get; private set; } = true;

    public BusinessParty(
        string partyCode,
        string partyName,
        string partyType,
        string countryCode = "EG",
        string? firmNationalId = null,
        string? taxRegistrationNumber = null,
        string? taxBranchCode = null,
        string? email = null,
        string? mobileNumber = null,
        string? addressLine1 = null,
        decimal? creditLimitAmount = null,
        int? creditTermsDays = null,
        bool isCreditHoldEnabled = false,
        string? creditHoldReason = null)
    {
        PartyCode = partyCode;
        PartyName = partyName;
        PartyType = partyType;
        CountryCode = countryCode;
        FirmNationalId = firmNationalId;
        TaxRegistrationNumber = taxRegistrationNumber;
        TaxBranchCode = taxBranchCode;
        Email = email;
        MobileNumber = mobileNumber;
        AddressLine1 = addressLine1;
        CreditLimitAmount = creditLimitAmount;
        CreditTermsDays = creditTermsDays;
        IsCreditHoldEnabled = isCreditHoldEnabled;
        CreditHoldReason = creditHoldReason;
    }

    public void SetFirmNationalId(string? firmNationalId)
    {
        FirmNationalId = firmNationalId;
    }

    private BusinessParty()
    {
    }
}
