using CashLineERP.Domain.Audit;
using CashLineERP.Domain.Customers;
using CashLineERP.Domain.Documents;
using CashLineERP.Domain.Finance;
using CashLineERP.Domain.Integration;
using CashLineERP.Domain.Identity;
using CashLineERP.Domain.Inventory;
using CashLineERP.Domain.IslamicFinance.ContractTemplates;
using CashLineERP.Domain.IslamicFinance.Facilities;
using CashLineERP.Domain.IslamicFinance.Accounting;
using CashLineERP.Domain.IslamicFinance.Disbursements;
using CashLineERP.Domain.IslamicFinance.Murabaha;
using CashLineERP.Domain.IslamicFinance.Requests;
using CashLineERP.Domain.IslamicFinance.ReceivablesFinance;
using CashLineERP.Domain.IslamicFinance.Settlements;
using CashLineERP.Domain.IslamicFinance.Shariah;
using CashLineERP.Domain.IslamicFinance.PartnerLenders;
using CashLineERP.Domain.IslamicFinance.ProductProfiles;
using CashLineERP.Domain.Localization;
using CashLineERP.Domain.MasterData;
using CashLineERP.Domain.Notifications;
using CashLineERP.Domain.Organization;
using CashLineERP.Domain.Parties;
using CashLineERP.Domain.Procurement;
using CashLineERP.Domain.Reporting;
using CashLineERP.Domain.Sales;
using CashLineERP.Domain.Suppliers;
using CashLineERP.Domain.Tax;
using CashLineERP.Domain.Workflow;
using CashLineERP.SharedKernel.Finance;
using CashLineERP.SharedKernel.Identity;
using CashLineERP.SharedKernel.Localization;
using CashLineERP.SharedKernel.Workflow;
using Microsoft.EntityFrameworkCore;

namespace CashLineERP.Infrastructure.Persistence;

public sealed class CashLineErpDbContext : DbContext
{
    private static readonly DateTime SeedCreatedAtUtc = new(2026, 4, 1, 8, 0, 0, DateTimeKind.Utc);
    private static readonly DateTime SeedSubmittedAtUtc = new(2026, 4, 1, 9, 15, 0, DateTimeKind.Utc);
    private static readonly DateTime SeedEffectiveFromDate = new(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc);

    public CashLineErpDbContext(DbContextOptions<CashLineErpDbContext> options)
        : base(options)
    {
    }

    public DbSet<ApplicationUser> Users => Set<ApplicationUser>();

    public DbSet<Role> Roles => Set<Role>();

    public DbSet<IntegrationEndpointRegistryEntry> IntegrationEndpointRegistryEntries => Set<IntegrationEndpointRegistryEntry>();

    public DbSet<OutboxEvent> OutboxEvents => Set<OutboxEvent>();

    public DbSet<InboxMessage> InboxMessages => Set<InboxMessage>();

    public DbSet<UserRole> UserRoles => Set<UserRole>();

    public DbSet<UserFunctionAssignment> UserFunctionAssignments => Set<UserFunctionAssignment>();

    public DbSet<AccountingOfficeClientAssignment> AccountingOfficeClientAssignments => Set<AccountingOfficeClientAssignment>();

    public DbSet<AccountingOfficeClientRequest> AccountingOfficeClientRequests => Set<AccountingOfficeClientRequest>();

    public DbSet<PortalMenuSectionDefinition> PortalMenuSections => Set<PortalMenuSectionDefinition>();

    public DbSet<FunctionGovernanceDefinition> FunctionGovernanceDefinitions => Set<FunctionGovernanceDefinition>();

    public DbSet<Branch> Branches => Set<Branch>();

    public DbSet<BusinessParty> BusinessParties => Set<BusinessParty>();

    public DbSet<OnboardingLead> OnboardingLeads => Set<OnboardingLead>();

    public DbSet<OnboardingReviewChecklistItem> OnboardingReviewChecklistItems => Set<OnboardingReviewChecklistItem>();

    public DbSet<OnboardingReviewFinding> OnboardingReviewFindings => Set<OnboardingReviewFinding>();

    public DbSet<SupplierProfile> SupplierProfiles => Set<SupplierProfile>();

    public DbSet<CustomerProfile> CustomerProfiles => Set<CustomerProfile>();

    public DbSet<CounterpartyDocumentWorkflow> CounterpartyDocumentWorkflows => Set<CounterpartyDocumentWorkflow>();

    public DbSet<CustomerServiceRequest> CustomerServiceRequests => Set<CustomerServiceRequest>();

    public DbSet<IslamicFinancePartnerLender> IslamicFinancePartnerLenders => Set<IslamicFinancePartnerLender>();

    public DbSet<IslamicFinanceProductProfile> IslamicFinanceProductProfiles => Set<IslamicFinanceProductProfile>();

    public DbSet<IslamicFinanceContractTemplate> IslamicFinanceContractTemplates => Set<IslamicFinanceContractTemplate>();

    public DbSet<IslamicFinanceFacility> IslamicFinanceFacilities => Set<IslamicFinanceFacility>();

    public DbSet<IslamicFinanceRequest> IslamicFinanceRequests => Set<IslamicFinanceRequest>();

    public DbSet<IslamicFinanceDecision> IslamicFinanceDecisions => Set<IslamicFinanceDecision>();

    public DbSet<IslamicFinanceReceivablesCase> IslamicFinanceReceivablesCases => Set<IslamicFinanceReceivablesCase>();

    public DbSet<IslamicFinanceReceivablesCaseLine> IslamicFinanceReceivablesCaseLines => Set<IslamicFinanceReceivablesCaseLine>();

    public DbSet<IslamicFinanceShariahReviewCase> IslamicFinanceShariahReviewCases => Set<IslamicFinanceShariahReviewCase>();

    public DbSet<IslamicFinanceMurabahaCase> IslamicFinanceMurabahaCases => Set<IslamicFinanceMurabahaCase>();

    public DbSet<IslamicFinanceMurabahaAsset> IslamicFinanceMurabahaAssets => Set<IslamicFinanceMurabahaAsset>();

    public DbSet<IslamicFinanceMurabahaDisbursement> IslamicFinanceMurabahaDisbursements => Set<IslamicFinanceMurabahaDisbursement>();

    public DbSet<IslamicFinanceSettlementHeader> IslamicFinanceSettlementHeaders => Set<IslamicFinanceSettlementHeader>();

    public DbSet<IslamicFinanceSettlementLine> IslamicFinanceSettlementLines => Set<IslamicFinanceSettlementLine>();

    public DbSet<IslamicFinanceProfitSchedule> IslamicFinanceProfitSchedules => Set<IslamicFinanceProfitSchedule>();

    public DbSet<IslamicFinanceAccountingHook> IslamicFinanceAccountingHooks => Set<IslamicFinanceAccountingHook>();

    public DbSet<PurchaseRequisition> PurchaseRequisitions => Set<PurchaseRequisition>();

    public DbSet<PurchaseRequisitionLine> PurchaseRequisitionLines => Set<PurchaseRequisitionLine>();

    public DbSet<RequestForQuotation> RequestForQuotations => Set<RequestForQuotation>();

    public DbSet<RequestForQuotationLine> RequestForQuotationLines => Set<RequestForQuotationLine>();

    public DbSet<RequestForQuotationSupplier> RequestForQuotationSuppliers => Set<RequestForQuotationSupplier>();

    public DbSet<SupplierQuotation> SupplierQuotations => Set<SupplierQuotation>();

    public DbSet<SupplierQuotationLine> SupplierQuotationLines => Set<SupplierQuotationLine>();

    public DbSet<RfqEvaluation> RfqEvaluations => Set<RfqEvaluation>();

    public DbSet<RfqEvaluationLine> RfqEvaluationLines => Set<RfqEvaluationLine>();

    public DbSet<PurchaseOrder> PurchaseOrders => Set<PurchaseOrder>();

    public DbSet<PurchaseOrderLine> PurchaseOrderLines => Set<PurchaseOrderLine>();

    public DbSet<GoodsReceipt> GoodsReceipts => Set<GoodsReceipt>();

    public DbSet<GoodsReceiptLine> GoodsReceiptLines => Set<GoodsReceiptLine>();

    public DbSet<PurchaseReturn> PurchaseReturns => Set<PurchaseReturn>();

    public DbSet<PurchaseReturnLine> PurchaseReturnLines => Set<PurchaseReturnLine>();

    public DbSet<AccountsPayableBill> AccountsPayableBills => Set<AccountsPayableBill>();

    public DbSet<AccountsPayableBillLine> AccountsPayableBillLines => Set<AccountsPayableBillLine>();

    public DbSet<PricingRule> PricingRules => Set<PricingRule>();

    public DbSet<SalesDiscountOverride> SalesDiscountOverrides => Set<SalesDiscountOverride>();

    public DbSet<SalesOrder> SalesOrders => Set<SalesOrder>();

    public DbSet<SalesOrderLine> SalesOrderLines => Set<SalesOrderLine>();

    public DbSet<SalesReturn> SalesReturns => Set<SalesReturn>();

    public DbSet<SalesReturnLine> SalesReturnLines => Set<SalesReturnLine>();

    public DbSet<DispatchOrder> DispatchOrders => Set<DispatchOrder>();

    public DbSet<DispatchOrderLine> DispatchOrderLines => Set<DispatchOrderLine>();

    public DbSet<AccountsReceivableInvoice> AccountsReceivableInvoices => Set<AccountsReceivableInvoice>();

    public DbSet<AccountsReceivableInvoiceLine> AccountsReceivableInvoiceLines => Set<AccountsReceivableInvoiceLine>();

    public DbSet<AccountsReceivableReceipt> AccountsReceivableReceipts => Set<AccountsReceivableReceipt>();

    public DbSet<AccountsReceivableReceiptAllocation> AccountsReceivableReceiptAllocations => Set<AccountsReceivableReceiptAllocation>();

    public DbSet<CustomerPaymentRequest> CustomerPaymentRequests => Set<CustomerPaymentRequest>();

    public DbSet<CustomerRefund> CustomerRefunds => Set<CustomerRefund>();

    public DbSet<PaymentGatewayExecution> PaymentGatewayExecutions => Set<PaymentGatewayExecution>();

    public DbSet<AccountsPayablePayment> AccountsPayablePayments => Set<AccountsPayablePayment>();

    public DbSet<AccountsPayablePaymentAllocation> AccountsPayablePaymentAllocations => Set<AccountsPayablePaymentAllocation>();

    public DbSet<BankTransferBatch> BankTransferBatches => Set<BankTransferBatch>();

    public DbSet<BankTransferBatchLine> BankTransferBatchLines => Set<BankTransferBatchLine>();

    public DbSet<PaymentSettlementBatch> PaymentSettlementBatches => Set<PaymentSettlementBatch>();

    public DbSet<PaymentSettlementBatchLine> PaymentSettlementBatchLines => Set<PaymentSettlementBatchLine>();

    public DbSet<PaymentSettlementException> PaymentSettlementExceptions => Set<PaymentSettlementException>();

    public DbSet<CashAccount> CashAccounts => Set<CashAccount>();

    public DbSet<TreasuryTransfer> TreasuryTransfers => Set<TreasuryTransfer>();

    public DbSet<ForeignExchangeQuote> ForeignExchangeQuotes => Set<ForeignExchangeQuote>();

    public DbSet<ForeignExchangeOverride> ForeignExchangeOverrides => Set<ForeignExchangeOverride>();

    public DbSet<ForeignExchangeRevaluation> ForeignExchangeRevaluations => Set<ForeignExchangeRevaluation>();

    public DbSet<ForeignExchangeRevaluationLine> ForeignExchangeRevaluationLines => Set<ForeignExchangeRevaluationLine>();

    public DbSet<CardTokenReference> CardTokenReferences => Set<CardTokenReference>();

    public DbSet<PaymentChannelConfiguration> PaymentChannelConfigurations => Set<PaymentChannelConfiguration>();

    public DbSet<WalletRule> WalletRules => Set<WalletRule>();

    public DbSet<FinanceAccountingRule> FinanceAccountingRules => Set<FinanceAccountingRule>();

    public DbSet<CollectionsFollowUpAction> CollectionsFollowUpActions => Set<CollectionsFollowUpAction>();

    public DbSet<CustomerStatement> CustomerStatements => Set<CustomerStatement>();

    public DbSet<CustomerStatementLine> CustomerStatementLines => Set<CustomerStatementLine>();

    public DbSet<CustomerStatementDeliveryLog> CustomerStatementDeliveryLogs => Set<CustomerStatementDeliveryLog>();

    public DbSet<SupplierStatement> SupplierStatements => Set<SupplierStatement>();

    public DbSet<SupplierStatementLine> SupplierStatementLines => Set<SupplierStatementLine>();

    public DbSet<SupplierStatementDeliveryLog> SupplierStatementDeliveryLogs => Set<SupplierStatementDeliveryLog>();

    public DbSet<ReportingSnapshot> ReportingSnapshots => Set<ReportingSnapshot>();

    public DbSet<FinanceCloseJournal> FinanceCloseJournals => Set<FinanceCloseJournal>();

    public DbSet<FinanceCloseJournalLine> FinanceCloseJournalLines => Set<FinanceCloseJournalLine>();

    public DbSet<AccountingPeriod> AccountingPeriods => Set<AccountingPeriod>();

    public DbSet<BankStatement> BankStatements => Set<BankStatement>();

    public DbSet<BankStatementLine> BankStatementLines => Set<BankStatementLine>();

    public DbSet<ReceiptReconciliationRun> ReceiptReconciliationRuns => Set<ReceiptReconciliationRun>();

    public DbSet<ReceiptReconciliationItem> ReceiptReconciliationItems => Set<ReceiptReconciliationItem>();

    public DbSet<EtaSubmissionLog> EtaSubmissionLogs => Set<EtaSubmissionLog>();

    public DbSet<EtaTransmissionAttempt> EtaTransmissionAttempts => Set<EtaTransmissionAttempt>();

    public DbSet<EtaDocumentEvent> EtaDocumentEvents => Set<EtaDocumentEvent>();

    public DbSet<StockCount> StockCounts => Set<StockCount>();

    public DbSet<StockCountLine> StockCountLines => Set<StockCountLine>();

    public DbSet<WarehouseTransfer> WarehouseTransfers => Set<WarehouseTransfer>();

    public DbSet<WarehouseTransferLine> WarehouseTransferLines => Set<WarehouseTransferLine>();

    public DbSet<ReplenishmentRule> ReplenishmentRules => Set<ReplenishmentRule>();

    public DbSet<InventoryAdjustment> InventoryAdjustments => Set<InventoryAdjustment>();

    public DbSet<InventoryAdjustmentLine> InventoryAdjustmentLines => Set<InventoryAdjustmentLine>();

    public DbSet<InventoryStatusControl> InventoryStatusControls => Set<InventoryStatusControl>();

    public DbSet<InventoryStatusControlLine> InventoryStatusControlLines => Set<InventoryStatusControlLine>();

    public DbSet<InventoryMovement> InventoryMovements => Set<InventoryMovement>();

    public DbSet<GeneralLedgerBatch> GeneralLedgerBatches => Set<GeneralLedgerBatch>();

    public DbSet<GeneralLedgerJournal> GeneralLedgerJournals => Set<GeneralLedgerJournal>();

    public DbSet<GeneralLedgerJournalLine> GeneralLedgerJournalLines => Set<GeneralLedgerJournalLine>();

    public DbSet<WorkflowRule> WorkflowRules => Set<WorkflowRule>();

    public DbSet<WorkflowInstance> WorkflowInstances => Set<WorkflowInstance>();

    public DbSet<WorkflowAction> WorkflowActions => Set<WorkflowAction>();

    public DbSet<AuditEvent> AuditEvents => Set<AuditEvent>();

    public DbSet<DocumentLink> DocumentLinks => Set<DocumentLink>();

    public DbSet<NotificationQueueItem> NotificationQueueItems => Set<NotificationQueueItem>();

    public DbSet<NotificationTemplate> NotificationTemplates => Set<NotificationTemplate>();

    public DbSet<LocalizationResource> LocalizationResources => Set<LocalizationResource>();

    public DbSet<ReferenceDataEntry> ReferenceDataEntries => Set<ReferenceDataEntry>();

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        ConfigureRoles(modelBuilder);
        ConfigureBranches(modelBuilder);
        ConfigureUsers(modelBuilder);
        ConfigureParties(modelBuilder);
        ConfigureSupplierProfiles(modelBuilder);
        ConfigureCustomerProfiles(modelBuilder);
        ConfigureCounterpartyCollaboration(modelBuilder);
        ConfigureWorkflow(modelBuilder);
        ConfigureAudit(modelBuilder);
        ConfigureDocuments(modelBuilder);
        ConfigureLocalization(modelBuilder);
        ConfigureMasterDataGovernance(modelBuilder);
        ConfigureIslamicFinanceGovernance(modelBuilder);
        ConfigureNotifications(modelBuilder);
        ConfigureIntegrationRegistry(modelBuilder);
        ConfigureProcurement(modelBuilder);
        ConfigureSourcing(modelBuilder);
        ConfigureCommercialDecision(modelBuilder);
        ConfigureReceivingAndPayables(modelBuilder);
        ConfigureSalesAndDispatch(modelBuilder);
        ConfigurePricing(modelBuilder);
        ConfigureReceivables(modelBuilder);
        ConfigureCustomerPaymentRequests(modelBuilder);
        ConfigureCustomerRefunds(modelBuilder);
        ConfigurePayablesPayments(modelBuilder);
        ConfigureBankTransferBatches(modelBuilder);
        ConfigurePaymentSettlementBatches(modelBuilder);
        ConfigureTreasury(modelBuilder);
        ConfigureForeignExchangeQuotes(modelBuilder);
        ConfigureForeignExchangeOverrides(modelBuilder);
        ConfigureForeignExchangeRevaluations(modelBuilder);
        ConfigureCardTokenReferences(modelBuilder);
        ConfigurePaymentChannels(modelBuilder);
        ConfigureWalletRules(modelBuilder);
        ConfigureAccountingRules(modelBuilder);
        ConfigureCollections(modelBuilder);
        ConfigureCustomerStatements(modelBuilder);
        ConfigureSupplierStatements(modelBuilder);
        ConfigureEtaCompliance(modelBuilder);
        ConfigureInventoryAndFinanceTraceability(modelBuilder);
        ConfigureReconciliationAndClose(modelBuilder);
    }

    private static void ConfigureRoles(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Role>(builder =>
        {
            builder.ToTable("sec_role");
            builder.HasKey(role => role.Id);
            builder.Property(role => role.Id).HasColumnName("role_id");
            builder.Property(role => role.RoleCode).HasColumnName("role_code").HasMaxLength(60).IsRequired();
            builder.Property(role => role.RoleName).HasColumnName("role_name").HasMaxLength(200).IsRequired();
            builder.Property(role => role.PortalCode).HasColumnName("portal_code").HasMaxLength(30).IsRequired();
            builder.Property(role => role.IsChecker).HasColumnName("is_checker");
            builder.Property(role => role.IsActive).HasColumnName("is_active");
            builder.Property(role => role.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(role => role.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(role => role.UpdatedAtUtc);
            builder.Ignore(role => role.UpdatedByUserId);

            builder.HasData(
                new
                {
                    Id = 1L,
                    RoleCode = "SUPER_ADMIN",
                    RoleName = "Super Admin",
                    PortalCode = PortalCode.Internal,
                    IsChecker = true,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 2L,
                    RoleCode = "ADMIN",
                    RoleName = "Admin",
                    PortalCode = PortalCode.Internal,
                    IsChecker = false,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 3L,
                    RoleCode = "FINANCE_MAKER",
                    RoleName = "Finance Maker",
                    PortalCode = PortalCode.Internal,
                    IsChecker = false,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 4L,
                    RoleCode = "FINANCE_CHECKER",
                    RoleName = "Finance Checker",
                    PortalCode = PortalCode.Internal,
                    IsChecker = true,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 5L,
                    RoleCode = "SUPPLIER_ADMIN",
                    RoleName = "Supplier Organization Admin",
                    PortalCode = PortalCode.External,
                    IsChecker = false,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 6L,
                    RoleCode = "CUSTOMER_ADMIN",
                    RoleName = "Customer Organization Admin",
                    PortalCode = PortalCode.External,
                    IsChecker = false,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 7L,
                    RoleCode = "SYSTEM_OWNER",
                    RoleName = "System Owner",
                    PortalCode = PortalCode.Internal,
                    IsChecker = true,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 8L,
                    RoleCode = "ACCOUNTING_OFFICE_USER",
                    RoleName = "Accounting Office User",
                    PortalCode = PortalCode.Internal,
                    IsChecker = false,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 9L,
                    RoleCode = "ACCOUNTING_OFFICE_SUPERVISOR",
                    RoleName = "Accounting Office Supervisor",
                    PortalCode = PortalCode.Internal,
                    IsChecker = true,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                });
        });
    }

    private static void ConfigureBranches(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Branch>(builder =>
        {
            builder.ToTable("org_branch");
            builder.HasKey(branch => branch.Id);
            builder.Property(branch => branch.Id).HasColumnName("branch_id");
            builder.Property(branch => branch.CompanyId).HasColumnName("company_id");
            builder.Property(branch => branch.BranchCode).HasColumnName("branch_code").HasMaxLength(40).IsRequired();
            builder.Property(branch => branch.BranchName).HasColumnName("branch_name").HasMaxLength(200).IsRequired();
            builder.Property(branch => branch.BranchType).HasColumnName("branch_type").HasMaxLength(30).IsRequired();
            builder.Property(branch => branch.TaxBranchCode).HasColumnName("tax_branch_code").HasMaxLength(30);
            builder.Property(branch => branch.CountryCode).HasColumnName("country_code").HasMaxLength(10).IsRequired();
            builder.Property(branch => branch.IsActive).HasColumnName("is_active");
            builder.Property(branch => branch.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(branch => branch.CreatedByUserId).HasColumnName("created_by");
            builder.Property(branch => branch.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(branch => branch.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasData(new
            {
                Id = 1L,
                CompanyId = 1L,
                BranchCode = "HO",
                BranchName = "Head Office",
                BranchType = "OPERATING",
                TaxBranchCode = "001",
                CountryCode = "EG",
                IsActive = true,
                CreatedAtUtc = SeedCreatedAtUtc,
                CreatedByUserId = (long?)null,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });
    }

    private static void ConfigureUsers(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ApplicationUser>(builder =>
        {
            builder.ToTable("sec_user");
            builder.HasKey(user => user.Id);
            builder.Property(user => user.Id).HasColumnName("user_id");
            builder.Property(user => user.BranchId).HasColumnName("branch_id");
            builder.Property(user => user.LoginName).HasColumnName("login_name").HasMaxLength(100).IsRequired();
            builder.Property(user => user.DisplayName).HasColumnName("display_name").HasMaxLength(200).IsRequired();
            builder.Property(user => user.Email).HasColumnName("email").HasMaxLength(254);
            builder.Property(user => user.UserTypeCode).HasColumnName("user_type").HasMaxLength(30).IsRequired();
            builder.Property(user => user.PasswordHash).HasColumnName("password_hash").HasMaxLength(128).IsRequired();
            builder.Property(user => user.PartyId).HasColumnName("party_id");
            builder.Property(user => user.IsActive).HasColumnName("is_active");
            builder.Property(user => user.IsLocked).HasColumnName("is_locked");
            builder.Property(user => user.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(user => user.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(user => user.UpdatedAtUtc);
            builder.Ignore(user => user.UpdatedByUserId);

            builder.HasMany(user => user.Roles)
                .WithOne(userRole => userRole.User)
                .HasForeignKey(userRole => userRole.UserId);

            builder.HasMany(user => user.FunctionAssignments)
                .WithOne(userFunction => userFunction.User)
                .HasForeignKey(userFunction => userFunction.UserId);

            builder.HasData(
                new
                {
                    Id = 1L,
                    BranchId = 1L,
                    LoginName = "OPS_MKR01",
                    DisplayName = "Operations Maker 01",
                    Email = "ops.mkr01@cashline.local",
                    UserTypeCode = UserTypeCode.Internal,
                    PasswordHash = "FD1E4F8FE38F2470FB114867D35EEC0096C43073285E149BC09F8457E4F11C75",
                    PartyId = (long?)null,
                    IsActive = true,
                    IsLocked = false,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 2L,
                    BranchId = 1L,
                    LoginName = "FIN_CHK01",
                    DisplayName = "Finance Checker 01",
                    Email = "fin.chk01@cashline.local",
                    UserTypeCode = UserTypeCode.Internal,
                    PasswordHash = "6F69F0BCC96B43E263C14080D68EE406337A76A4B2C75B28D3880F081123C04E",
                    PartyId = (long?)null,
                    IsActive = true,
                    IsLocked = false,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 3L,
                    BranchId = (long?)null,
                    LoginName = "SUPPLIER_ADMIN01",
                    DisplayName = "Supplier Admin 01",
                    Email = "supplier.admin01@vendor.local",
                    UserTypeCode = UserTypeCode.External,
                    PasswordHash = "43B029C5F324F8A22E31832FBD5CD5DDBB38D05FF514FA60E16F5CA44495F430",
                    PartyId = 1L,
                    IsActive = true,
                    IsLocked = false,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 4L,
                    BranchId = (long?)null,
                    LoginName = "CUSTOMER_ADMIN01",
                    DisplayName = "Customer Admin 01",
                    Email = "customer.admin01@customer.local",
                    UserTypeCode = UserTypeCode.External,
                    PasswordHash = "1EAEB8963FE8F48BE464C92E5A2F16A77D2D18FAEDA825FCCC1948389E8AF739",
                    PartyId = 2L,
                    IsActive = true,
                    IsLocked = false,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 5L,
                    BranchId = 1L,
                    LoginName = "FIN_MKR01",
                    DisplayName = "Finance Maker 01",
                    Email = "fin.mkr01@cashline.local",
                    UserTypeCode = UserTypeCode.Internal,
                    PasswordHash = "3E8E1844EA18141BF935522FA411AB728C12CA8FA6ED815628FEE49717E9BD13",
                    PartyId = (long?)null,
                    IsActive = true,
                    IsLocked = false,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                },
                new
                {
                    Id = 6L,
                    BranchId = 1L,
                    LoginName = "ADMINISTRATOR",
                    DisplayName = "System Administrator",
                    Email = "administrator@uat.cashline.test",
                    UserTypeCode = UserTypeCode.Internal,
                    PasswordHash = "6F2CB9DD8F4B65E24E1C3F3FA5BC57982349237F11ABCEACD45BBCB74D621C25",
                    PartyId = (long?)null,
                    IsActive = true,
                    IsLocked = false,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null
                });
        });

        modelBuilder.Entity<UserRole>(builder =>
        {
            builder.ToTable("sec_user_role");
            builder.HasKey(userRole => userRole.Id);
            builder.Property(userRole => userRole.Id).HasColumnName("user_role_id");
            builder.Property(userRole => userRole.UserId).HasColumnName("user_id");
            builder.Property(userRole => userRole.RoleId).HasColumnName("role_id");
            builder.Property(userRole => userRole.EffectiveFromUtc).HasColumnName("effective_from").HasColumnType("date");
            builder.Property(userRole => userRole.EffectiveToUtc).HasColumnName("effective_to").HasColumnType("date");
            builder.Property(userRole => userRole.IsActive).HasColumnName("is_active");

            builder.HasOne(userRole => userRole.Role)
                .WithMany(role => role.UserAssignments)
                .HasForeignKey(userRole => userRole.RoleId);

            builder.HasData(
                new
                {
                    Id = 1L,
                    UserId = 1L,
                    RoleId = 2L,
                    EffectiveFromUtc = SeedEffectiveFromDate,
                    EffectiveToUtc = (DateTime?)null,
                    IsActive = true
                },
                new
                {
                    Id = 2L,
                    UserId = 2L,
                    RoleId = 4L,
                    EffectiveFromUtc = SeedEffectiveFromDate,
                    EffectiveToUtc = (DateTime?)null,
                    IsActive = true
                },
                new
                {
                    Id = 3L,
                    UserId = 3L,
                    RoleId = 5L,
                    EffectiveFromUtc = SeedEffectiveFromDate,
                    EffectiveToUtc = (DateTime?)null,
                    IsActive = true
                },
                new
                {
                    Id = 4L,
                    UserId = 4L,
                    RoleId = 6L,
                    EffectiveFromUtc = SeedEffectiveFromDate,
                    EffectiveToUtc = (DateTime?)null,
                    IsActive = true
                },
                new
                {
                    Id = 5L,
                    UserId = 5L,
                    RoleId = 3L,
                    EffectiveFromUtc = SeedEffectiveFromDate,
                    EffectiveToUtc = (DateTime?)null,
                    IsActive = true
                },
                new
                {
                    Id = 6L,
                    UserId = 6L,
                    RoleId = 1L,
                    EffectiveFromUtc = SeedEffectiveFromDate,
                    EffectiveToUtc = (DateTime?)null,
                    IsActive = true
                });
        });

        modelBuilder.Entity<UserFunctionAssignment>(builder =>
        {
            builder.ToTable("sec_user_function");
            builder.HasKey(userFunction => userFunction.Id);
            builder.Property(userFunction => userFunction.Id).HasColumnName("user_function_id");
            builder.Property(userFunction => userFunction.UserId).HasColumnName("user_id");
            builder.Property(userFunction => userFunction.FunctionCode).HasColumnName("function_code").HasMaxLength(80).IsRequired();
            builder.Property(userFunction => userFunction.EffectiveFromUtc).HasColumnName("effective_from").HasColumnType("date");
            builder.Property(userFunction => userFunction.EffectiveToUtc).HasColumnName("effective_to").HasColumnType("date");
            builder.Property(userFunction => userFunction.IsActive).HasColumnName("is_active");

            builder.HasData(
                new { Id = 1L, UserId = 1L, FunctionCode = "OPERATIONS_WORKBENCH", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 2L, UserId = 1L, FunctionCode = "ONBOARDING_REVIEW", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 3L, UserId = 1L, FunctionCode = "WORKFLOW_MONITORING", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 4L, UserId = 1L, FunctionCode = "OPERATIONAL_REPORTING", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 5L, UserId = 2L, FunctionCode = "FINANCE_REVIEW", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 6L, UserId = 2L, FunctionCode = "PAYMENT_APPROVAL", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 7L, UserId = 2L, FunctionCode = "STATEMENT_APPROVAL", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 8L, UserId = 2L, FunctionCode = "FINANCE_REPORTING", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 9L, UserId = 3L, FunctionCode = "SUPPLIER_ONBOARDING", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 10L, UserId = 3L, FunctionCode = "SUPPLIER_DOCUMENTS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 11L, UserId = 3L, FunctionCode = "SUPPLIER_PURCHASE_ORDERS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 12L, UserId = 3L, FunctionCode = "SUPPLIER_INVOICES", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 13L, UserId = 3L, FunctionCode = "SUPPLIER_STATEMENTS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 14L, UserId = 3L, FunctionCode = "SUPPLIER_NOTIFICATIONS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 15L, UserId = 4L, FunctionCode = "CUSTOMER_ONBOARDING", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 16L, UserId = 4L, FunctionCode = "CUSTOMER_DOCUMENTS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 17L, UserId = 4L, FunctionCode = "CUSTOMER_ORDERS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 18L, UserId = 4L, FunctionCode = "CUSTOMER_PAYMENTS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 19L, UserId = 4L, FunctionCode = "CUSTOMER_STATEMENTS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 20L, UserId = 4L, FunctionCode = "CUSTOMER_NOTIFICATIONS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 21L, UserId = 5L, FunctionCode = "FINANCE_PREPARATION", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 22L, UserId = 5L, FunctionCode = "PAYMENT_INITIATION", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 23L, UserId = 5L, FunctionCode = "STATEMENT_PREPARATION", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 24L, UserId = 5L, FunctionCode = "FINANCE_REPORTING", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 25L, UserId = 6L, FunctionCode = "CREATE_USERS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 26L, UserId = 6L, FunctionCode = "ASSIGN_ROLES", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 27L, UserId = 6L, FunctionCode = "CONFIGURE_USER_FUNCTIONS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 28L, UserId = 6L, FunctionCode = "SUSPEND_USERS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 29L, UserId = 6L, FunctionCode = "HOLD_USERS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 30L, UserId = 6L, FunctionCode = "REVOKE_USERS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 31L, UserId = 6L, FunctionCode = "DELETE_USERS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true },
                new { Id = 32L, UserId = 6L, FunctionCode = "EXPORT_USER_ADMIN_REPORTS", EffectiveFromUtc = SeedEffectiveFromDate, EffectiveToUtc = (DateTime?)null, IsActive = true });
        });

        modelBuilder.Entity<PortalMenuSectionDefinition>(builder =>
        {
            builder.ToTable("sec_portal_menu_section");
            builder.HasKey(section => section.Id);
            builder.Property(section => section.Id).HasColumnName("menu_section_id");
            builder.Property(section => section.PortalCode).HasColumnName("portal_code").HasMaxLength(30).IsRequired();
            builder.Property(section => section.UserTypeCode).HasColumnName("user_type_code").HasMaxLength(30).IsRequired();
            builder.Property(section => section.SectionCode).HasColumnName("section_code").HasMaxLength(80).IsRequired();
            builder.Property(section => section.SectionLabel).HasColumnName("section_label").HasMaxLength(200).IsRequired();
            builder.Property(section => section.DisplayOrder).HasColumnName("display_order");
            builder.Property(section => section.IsEnabled).HasColumnName("is_enabled");
            builder.Property(section => section.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(section => section.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<FunctionGovernanceDefinition>(builder =>
        {
            builder.ToTable("sec_function_governance");
            builder.HasKey(function => function.Id);
            builder.Property(function => function.Id).HasColumnName("function_governance_id");
            builder.Property(function => function.FunctionCode).HasColumnName("function_code").HasMaxLength(80).IsRequired();
            builder.Property(function => function.FunctionLabel).HasColumnName("function_label").HasMaxLength(200).IsRequired();
            builder.Property(function => function.MenuSectionCode).HasColumnName("menu_section_code").HasMaxLength(80).IsRequired();
            builder.Property(function => function.PortalCode).HasColumnName("portal_code").HasMaxLength(30).IsRequired();
            builder.Property(function => function.UserTypeCode).HasColumnName("user_type_code").HasMaxLength(30).IsRequired();
            builder.Property(function => function.Route).HasColumnName("route").HasMaxLength(200).IsRequired();
            builder.Property(function => function.StepId).HasColumnName("step_id").HasMaxLength(120).IsRequired();
            builder.Property(function => function.PermissionCode).HasColumnName("permission_code").HasMaxLength(120).IsRequired();
            builder.Property(function => function.RuleCode).HasColumnName("rule_code").HasMaxLength(160).IsRequired();
            builder.Property(function => function.DisplayOrder).HasColumnName("display_order");
            builder.Property(function => function.IsEnabled).HasColumnName("is_enabled");
            builder.Property(function => function.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(function => function.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<AccountingOfficeClientAssignment>(builder =>
        {
            builder.ToTable("sec_accounting_office_client");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("assignment_id");
            builder.Property(entry => entry.AccountingOfficeUserId).HasColumnName("accounting_office_user_id");
            builder.Property(entry => entry.ClientPartyId).HasColumnName("client_party_id");
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.RevokedAtUtc).HasColumnName("revoked_at");
            builder.Property(entry => entry.RevokedByUserId).HasColumnName("revoked_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasOne(entry => entry.AccountingOfficeUser)
                .WithMany()
                .HasForeignKey(entry => entry.AccountingOfficeUserId)
                .OnDelete(DeleteBehavior.Cascade);

            builder.HasIndex(entry => new { entry.AccountingOfficeUserId, entry.ClientPartyId }).IsUnique();
        });

        modelBuilder.Entity<AccountingOfficeClientRequest>(builder =>
        {
            builder.ToTable("ao_client_request");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("ao_req_id");
            builder.Property(entry => entry.ClientPartyId).HasColumnName("client_party_id");
            builder.Property(entry => entry.AssignedAccountingOfficeUserId).HasColumnName("assigned_office_user_id");
            builder.Property(entry => entry.RequestNumber).HasColumnName("req_no").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.RequestTypeCode).HasColumnName("req_type").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.SubjectText).HasColumnName("subject_text").HasMaxLength(200).IsRequired();
            builder.Property(entry => entry.DetailsText).HasColumnName("details_text").HasMaxLength(2000).IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ReviewedAtUtc).HasColumnName("reviewed_at");
            builder.Property(entry => entry.ReviewedByUserId).HasColumnName("reviewed_by");
            builder.Property(entry => entry.CompletedAtUtc).HasColumnName("completed_at");
            builder.Property(entry => entry.CompletedByUserId).HasColumnName("completed_by");
            builder.Property(entry => entry.CompletionNotesText).HasColumnName("completion_notes").HasMaxLength(2000);
            builder.Property(entry => entry.RejectedAtUtc).HasColumnName("rejected_at");
            builder.Property(entry => entry.RejectedByUserId).HasColumnName("rejected_by");
            builder.Property(entry => entry.RejectionReasonText).HasColumnName("rejection_reason").HasMaxLength(2000);
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.ClientPartyId);
            builder.HasIndex(entry => entry.AssignedAccountingOfficeUserId);
        });
    }

    private static void ConfigureParties(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<BusinessParty>(builder =>
        {
            builder.ToTable("bp_party");
            builder.HasKey(party => party.Id);
            builder.Property(party => party.Id).HasColumnName("party_id");
            builder.Property(party => party.PartyCode).HasColumnName("party_code").HasMaxLength(60).IsRequired();
            builder.Property(party => party.PartyName).HasColumnName("party_name").HasMaxLength(200).IsRequired();
            builder.Property(party => party.PartyType).HasColumnName("party_type").HasMaxLength(30).IsRequired();
            builder.Property(party => party.CountryCode).HasColumnName("country_code").HasMaxLength(10).IsRequired();
            builder.Property(party => party.FirmNationalId).HasColumnName("firm_national_id").HasMaxLength(60);
            builder.Property(party => party.TaxRegistrationNumber).HasColumnName("tax_reg_no").HasMaxLength(50);
            builder.Property(party => party.TaxBranchCode).HasColumnName("tax_branch_code").HasMaxLength(30);
            builder.Property(party => party.Email).HasColumnName("email").HasMaxLength(254);
            builder.Property(party => party.MobileNumber).HasColumnName("mobile_no").HasMaxLength(40);
            builder.Property(party => party.AddressLine1).HasColumnName("addr_line1").HasMaxLength(255);
            builder.Property(party => party.CreditLimitAmount).HasColumnName("credit_limit_amt").HasPrecision(18, 2);
            builder.Property(party => party.CreditTermsDays).HasColumnName("credit_terms_days");
            builder.Property(party => party.IsCreditHoldEnabled).HasColumnName("is_credit_hold");
            builder.Property(party => party.CreditHoldReason).HasColumnName("credit_hold_reason").HasMaxLength(500);
            builder.Property(party => party.IsActive).HasColumnName("is_active");
            builder.Property(party => party.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(party => party.CreatedByUserId).HasColumnName("created_by");
            builder.Property(party => party.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(party => party.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(party => party.FirmNationalId).IsUnique();

            builder.HasData(
                new
                {
                    Id = 1L,
                    PartyCode = "SUP-0001",
                    PartyName = "Nile Industrial Supplies",
                    PartyType = "SUPPLIER",
                    CountryCode = "EG",
                    FirmNationalId = (string?)null,
                    TaxRegistrationNumber = "123456789",
                    TaxBranchCode = "001",
                    Email = "supply@nileindustrial.example",
                    MobileNumber = "+201000000001",
                    AddressLine1 = "Nasr City, Cairo",
                    CreditLimitAmount = (decimal?)null,
                    CreditTermsDays = (int?)null,
                    IsCreditHoldEnabled = false,
                    CreditHoldReason = (string?)null,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 2L,
                    PartyCode = "CUS-0001",
                    PartyName = "Cairo Retail Group",
                    PartyType = "CUSTOMER",
                    CountryCode = "EG",
                    FirmNationalId = (string?)null,
                    TaxRegistrationNumber = "987654321",
                    TaxBranchCode = "001",
                    Email = "ap@cairoretail.example",
                    MobileNumber = "+201000000002",
                    AddressLine1 = "New Cairo, Cairo",
                    CreditLimitAmount = 5000m,
                    CreditTermsDays = 30,
                    IsCreditHoldEnabled = false,
                    CreditHoldReason = (string?)null,
                    IsActive = true,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                });
        });

        modelBuilder.Entity<OnboardingLead>(builder =>
        {
            builder.ToTable("bp_onboarding_lead");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("bp_onboarding_lead_id");
            builder.Property(entry => entry.LeadCode).HasColumnName("lead_code").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.ProspectTypeCode).HasColumnName("prospect_type_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CompanyName).HasColumnName("company_name").HasMaxLength(200);
            builder.Property(entry => entry.ContactName).HasColumnName("contact_name").HasMaxLength(200);
            builder.Property(entry => entry.Email).HasColumnName("email").HasMaxLength(254);
            builder.Property(entry => entry.MobileNumber).HasColumnName("mobile_no").HasMaxLength(40);
            builder.Property(entry => entry.SourceChannelCode).HasColumnName("source_channel_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.Notes).HasColumnName("notes_txt").HasMaxLength(2000);
            builder.Property(entry => entry.BusinessPartyId).HasColumnName("party_id");
            builder.Property(entry => entry.SubjectProfileId).HasColumnName("subject_profile_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.LeadCode).IsUnique();
        });

        modelBuilder.Entity<OnboardingReviewChecklistItem>(builder =>
        {
            builder.ToTable("bp_onboarding_review_item");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("bp_onboarding_review_item_id");
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("wf_inst_id");
            builder.Property(entry => entry.SubjectTypeCode).HasColumnName("subject_type_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.SubjectProfileId).HasColumnName("subject_profile_id");
            builder.Property(entry => entry.ChecklistItemCode).HasColumnName("checklist_item_code").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.DisplayName).HasColumnName("display_name").HasMaxLength(200).IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.CoverageCode).HasColumnName("coverage_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.ReviewerNotesText).HasColumnName("reviewer_notes_txt").HasMaxLength(2000);
            builder.Property(entry => entry.ReviewedAtUtc).HasColumnName("reviewed_at");
            builder.Property(entry => entry.ReviewedByUserId).HasColumnName("reviewed_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => new { entry.WorkflowInstanceId, entry.ChecklistItemCode }).IsUnique();

            builder.HasOne<WorkflowInstance>()
                .WithMany()
                .HasForeignKey(entry => entry.WorkflowInstanceId)
                .OnDelete(DeleteBehavior.Restrict);
        });

        modelBuilder.Entity<OnboardingReviewFinding>(builder =>
        {
            builder.ToTable("bp_onboarding_review_finding");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("bp_onboarding_review_finding_id");
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("wf_inst_id");
            builder.Property(entry => entry.SubjectTypeCode).HasColumnName("subject_type_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.SubjectProfileId).HasColumnName("subject_profile_id");
            builder.Property(entry => entry.FindingCode).HasColumnName("finding_code").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.SeverityCode).HasColumnName("severity_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.RelatedItemCode).HasColumnName("related_item_code").HasMaxLength(60);
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.FindingText).HasColumnName("finding_txt").HasMaxLength(4000).IsRequired();
            builder.Property(entry => entry.LoggedAtUtc).HasColumnName("logged_at");
            builder.Property(entry => entry.LoggedByUserId).HasColumnName("logged_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasOne<WorkflowInstance>()
                .WithMany()
                .HasForeignKey(entry => entry.WorkflowInstanceId)
                .OnDelete(DeleteBehavior.Restrict);
        });
    }

    private static void ConfigureWorkflow(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<WorkflowRule>(builder =>
        {
            builder.ToTable("wf_rule");
            builder.HasKey(rule => rule.Id);
            builder.Property(rule => rule.Id).HasColumnName("rule_id");
            builder.Property(rule => rule.ModuleCode).HasColumnName("module_code").HasMaxLength(30).IsRequired();
            builder.Property(rule => rule.DocumentType).HasColumnName("doc_type").HasMaxLength(30).IsRequired();
            builder.Property(rule => rule.ActionCode).HasColumnName("action_code").HasMaxLength(30).IsRequired();
            builder.Property(rule => rule.MakerRoleCode).HasColumnName("maker_role_code").HasMaxLength(60);
            builder.Property(rule => rule.CheckerRoleCode).HasColumnName("checker_role_code").HasMaxLength(60);
            builder.Property(rule => rule.ThresholdAmount).HasColumnName("threshold_amt").HasPrecision(18, 2);
            builder.Property(rule => rule.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10);
            builder.Property(rule => rule.BranchId).HasColumnName("branch_id");
            builder.Property(rule => rule.IsActive).HasColumnName("is_active");

            builder.HasData(new
            {
                Id = 1L,
                ModuleCode = "PROCUREMENT",
                DocumentType = "PURCHASE_REQUISITION",
                ActionCode = "APPROVE",
                MakerRoleCode = "ADMIN",
                CheckerRoleCode = "FINANCE_CHECKER",
                ThresholdAmount = 0m,
                CurrencyCode = "EGP",
                BranchId = 1L,
                IsActive = true
            });
        });

        modelBuilder.Entity<WorkflowInstance>(builder =>
        {
            builder.ToTable("wf_inst");
            builder.HasKey(instance => instance.Id);
            builder.Property(instance => instance.Id).HasColumnName("wf_inst_id");
            builder.Property(instance => instance.ModuleCode).HasColumnName("module_code").HasMaxLength(30).IsRequired();
            builder.Property(instance => instance.DocumentType).HasColumnName("doc_type").HasMaxLength(30).IsRequired();
            builder.Property(instance => instance.DocumentId).HasColumnName("doc_id");
            builder.Property(instance => instance.WorkflowRuleId).HasColumnName("rule_id");
            builder.Property(instance => instance.MakerUserId).HasColumnName("maker_user_id");
            builder.Property(instance => instance.CheckerUserId).HasColumnName("checker_user_id");
            builder.Property(instance => instance.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(instance => instance.DecidedAtUtc).HasColumnName("decided_at");
            builder.Property(instance => instance.CurrentStatusCode).HasColumnName("current_status_code").HasMaxLength(30).IsRequired();
            builder.Property(instance => instance.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(instance => instance.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(instance => instance.UpdatedAtUtc);
            builder.Ignore(instance => instance.UpdatedByUserId);

            builder.HasMany(instance => instance.Actions)
                .WithOne()
                .HasForeignKey(action => action.WorkflowInstanceId);

            builder.HasData(new
            {
                Id = 1L,
                ModuleCode = "PROCUREMENT",
                DocumentType = "PURCHASE_REQUISITION",
                DocumentId = 1L,
                WorkflowRuleId = 1L,
                MakerUserId = 1L,
                CheckerUserId = 2L,
                SubmittedAtUtc = (DateTime?)SeedSubmittedAtUtc,
                DecidedAtUtc = (DateTime?)null,
                CurrentStatusCode = WorkflowStatusCode.Submitted,
                CreatedAtUtc = SeedSubmittedAtUtc,
                CreatedByUserId = 1L
            });
        });

        modelBuilder.Entity<WorkflowAction>(builder =>
        {
            builder.ToTable("wf_act");
            builder.HasKey(action => action.Id);
            builder.Property(action => action.Id).HasColumnName("wf_act_id");
            builder.Property(action => action.WorkflowInstanceId).HasColumnName("wf_inst_id");
            builder.Property(action => action.ActionCode).HasColumnName("action_code").HasMaxLength(30).IsRequired();
            builder.Property(action => action.PreviousStatusCode).HasColumnName("from_status_code").HasMaxLength(30).IsRequired();
            builder.Property(action => action.NewStatusCode).HasColumnName("to_status_code").HasMaxLength(30).IsRequired();
            builder.Property(action => action.ActorUserId).HasColumnName("acted_by");
            builder.Property(action => action.OccurredAtUtc).HasColumnName("acted_at");
            builder.Property(action => action.Comment).HasColumnName("comments_txt").HasMaxLength(1000);

            builder.HasData(new
            {
                Id = 1L,
                WorkflowInstanceId = 1L,
                ActionCode = "SUBMIT",
                PreviousStatusCode = WorkflowStatusCode.Draft,
                NewStatusCode = WorkflowStatusCode.Submitted,
                ActorUserId = 1L,
                OccurredAtUtc = SeedSubmittedAtUtc,
                Comment = "Initial requisition submitted for checker review."
            });
        });
    }

    private static void ConfigureSupplierProfiles(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<SupplierProfile>(builder =>
        {
            builder.ToTable("bp_supplier_profile");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("supplier_profile_id");
            builder.Property(entry => entry.SupplierProfileCode).HasColumnName("supplier_profile_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.BusinessPartyId).HasColumnName("party_id");
            builder.Property(entry => entry.SupplierCategoryCode).HasColumnName("supplier_category_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.DefaultCurrencyCode).HasColumnName("default_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.PreferredPaymentMethodCode).HasColumnName("payment_method_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.PaymentTermsDays).HasColumnName("payment_terms_days");
            builder.Property(entry => entry.LeadTimeDays).HasColumnName("lead_time_days");
            builder.Property(entry => entry.MinimumOrderAmount).HasColumnName("minimum_order_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.BankName).HasColumnName("bank_name").HasMaxLength(200).IsRequired();
            builder.Property(entry => entry.BankAccountNumber).HasColumnName("bank_account_number").HasMaxLength(100).IsRequired();
            builder.Property(entry => entry.BankSwiftCode).HasColumnName("bank_swift_code").HasMaxLength(30);
            builder.Property(entry => entry.BankVerificationStatusCode).HasColumnName("bank_verification_status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.BankVerifiedAtUtc).HasColumnName("bank_verified_at");
            builder.Property(entry => entry.BankVerifiedByUserId).HasColumnName("bank_verified_by");
            builder.Property(entry => entry.BankVerificationReference).HasColumnName("bank_verification_reference").HasMaxLength(100);
            builder.Property(entry => entry.RiskRatingCode).HasColumnName("risk_rating_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.PerformanceScore).HasColumnName("performance_score").HasPrecision(5, 2);
            builder.Property(entry => entry.OnTimeDeliveryScore).HasColumnName("on_time_delivery_score").HasPrecision(5, 2);
            builder.Property(entry => entry.QualityScore).HasColumnName("quality_score").HasPrecision(5, 2);
            builder.Property(entry => entry.LastPerformanceReviewAtUtc).HasColumnName("last_performance_review_at");
            builder.Property(entry => entry.LastPerformanceReviewedByUserId).HasColumnName("last_performance_reviewed_by");
            builder.Property(entry => entry.PerformanceNotes).HasColumnName("performance_notes").HasMaxLength(500);
            builder.Property(entry => entry.ComplianceStatusCode).HasColumnName("compliance_status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.StatusId).HasColumnName("status_id");
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.IsOnHold).HasColumnName("is_on_hold");
            builder.Property(entry => entry.HoldReason).HasColumnName("hold_reason").HasMaxLength(1000);
            builder.Property(entry => entry.HeldAtUtc).HasColumnName("held_at");
            builder.Property(entry => entry.HeldByUserId).HasColumnName("held_by");
            builder.Property(entry => entry.ReviewDecisionNotes).HasColumnName("review_decision_notes").HasMaxLength(1000);
            builder.Property(entry => entry.ReopenedAtUtc).HasColumnName("reopened_at");
            builder.Property(entry => entry.ReopenedByUserId).HasColumnName("reopened_by");
            builder.Property(entry => entry.ReopenReason).HasColumnName("reopen_reason").HasMaxLength(1000);
            builder.Property(entry => entry.Notes).HasColumnName("notes").HasMaxLength(500);
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.SupplierProfileCode).IsUnique();
            builder.HasIndex(entry => entry.BusinessPartyId).IsUnique();

            builder.HasOne<BusinessParty>()
                .WithMany()
                .HasForeignKey(entry => entry.BusinessPartyId)
                .OnDelete(DeleteBehavior.Restrict);
        });
    }

    private static void ConfigureCustomerProfiles(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<CustomerProfile>(builder =>
        {
            builder.ToTable("bp_customer_profile");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("customer_profile_id");
            builder.Property(entry => entry.CustomerProfileCode).HasColumnName("customer_profile_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.BusinessPartyId).HasColumnName("party_id");
            builder.Property(entry => entry.CustomerClassificationCode).HasColumnName("customer_classification_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CustomerSegmentCode).HasColumnName("customer_segment_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.DefaultCurrencyCode).HasColumnName("default_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.SalesChannelCode).HasColumnName("sales_channel_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.PriceTierCode).HasColumnName("price_tier_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.InvoiceDeliveryMethodCode).HasColumnName("invoice_delivery_method_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.TaxProfileStatusCode).HasColumnName("tax_profile_status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.StatusId).HasColumnName("status_id");
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.IsOnHold).HasColumnName("is_on_hold");
            builder.Property(entry => entry.HoldReason).HasColumnName("hold_reason").HasMaxLength(1000);
            builder.Property(entry => entry.HeldAtUtc).HasColumnName("held_at");
            builder.Property(entry => entry.HeldByUserId).HasColumnName("held_by");
            builder.Property(entry => entry.ReviewDecisionNotes).HasColumnName("review_decision_notes").HasMaxLength(1000);
            builder.Property(entry => entry.ReopenedAtUtc).HasColumnName("reopened_at");
            builder.Property(entry => entry.ReopenedByUserId).HasColumnName("reopened_by");
            builder.Property(entry => entry.ReopenReason).HasColumnName("reopen_reason").HasMaxLength(1000);
            builder.Property(entry => entry.Notes).HasColumnName("notes").HasMaxLength(500);
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.CustomerProfileCode).IsUnique();
            builder.HasIndex(entry => entry.BusinessPartyId).IsUnique();

            builder.HasOne<BusinessParty>()
                .WithMany()
                .HasForeignKey(entry => entry.BusinessPartyId)
                .OnDelete(DeleteBehavior.Restrict);
        });
    }

    private static void ConfigureCounterpartyCollaboration(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<CounterpartyDocumentWorkflow>(builder =>
        {
            builder.ToTable("bp_document_workflow");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("bp_document_workflow_id");
            builder.Property(entry => entry.PartyId).HasColumnName("party_id");
            builder.Property(entry => entry.PartyTypeCode).HasColumnName("party_type_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CurrentDocumentLinkId).HasColumnName("current_doc_link_id");
            builder.Property(entry => entry.DocumentTypeCode).HasColumnName("document_type_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.WorkflowNotesText).HasColumnName("workflow_notes_txt").HasMaxLength(1000);
            builder.Property(entry => entry.ReviewNotesText).HasColumnName("review_notes_txt").HasMaxLength(1000);
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ReviewedAtUtc).HasColumnName("reviewed_at");
            builder.Property(entry => entry.ReviewedByUserId).HasColumnName("reviewed_by");
            builder.Property(entry => entry.ReturnedAtUtc).HasColumnName("returned_at");
            builder.Property(entry => entry.ReturnedByUserId).HasColumnName("returned_by");
            builder.Property(entry => entry.RejectedAtUtc).HasColumnName("rejected_at");
            builder.Property(entry => entry.RejectedByUserId).HasColumnName("rejected_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasOne<BusinessParty>()
                .WithMany()
                .HasForeignKey(entry => entry.PartyId)
                .OnDelete(DeleteBehavior.Restrict);

            builder.HasOne<DocumentLink>()
                .WithMany()
                .HasForeignKey(entry => entry.CurrentDocumentLinkId)
                .OnDelete(DeleteBehavior.Restrict);
        });

        modelBuilder.Entity<CustomerServiceRequest>(builder =>
        {
            builder.ToTable("cust_service_request");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("cust_service_request_id");
            builder.Property(entry => entry.CustomerPartyId).HasColumnName("customer_party_id");
            builder.Property(entry => entry.RequestNumber).HasColumnName("request_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.RequestTypeCode).HasColumnName("request_type_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.SubjectText).HasColumnName("subject_txt").HasMaxLength(255).IsRequired();
            builder.Property(entry => entry.DetailsText).HasColumnName("details_txt").HasMaxLength(4000).IsRequired();
            builder.Property(entry => entry.PriorityCode).HasColumnName("priority_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CommercialImpactCode).HasColumnName("commercial_impact_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.RequestedResolutionCode).HasColumnName("requested_resolution_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.AssignedBackofficeLaneCode).HasColumnName("assigned_backoffice_lane_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.EscalationLevel).HasColumnName("escalation_level");
            builder.Property(entry => entry.RelatedDocumentType).HasColumnName("related_document_type").HasMaxLength(40);
            builder.Property(entry => entry.RelatedDocumentId).HasColumnName("related_document_id");
            builder.Property(entry => entry.InternalResponseText).HasColumnName("internal_response_txt").HasMaxLength(4000);
            builder.Property(entry => entry.EscalationReasonText).HasColumnName("escalation_reason_txt").HasMaxLength(4000);
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ReviewedAtUtc).HasColumnName("reviewed_at");
            builder.Property(entry => entry.ReviewedByUserId).HasColumnName("reviewed_by");
            builder.Property(entry => entry.EscalatedAtUtc).HasColumnName("escalated_at");
            builder.Property(entry => entry.EscalatedByUserId).HasColumnName("escalated_by");
            builder.Property(entry => entry.RespondedAtUtc).HasColumnName("responded_at");
            builder.Property(entry => entry.RespondedByUserId).HasColumnName("responded_by");
            builder.Property(entry => entry.RejectedAtUtc).HasColumnName("rejected_at");
            builder.Property(entry => entry.RejectedByUserId).HasColumnName("rejected_by");
            builder.Property(entry => entry.ClosedAtUtc).HasColumnName("closed_at");
            builder.Property(entry => entry.ClosedByUserId).HasColumnName("closed_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.RequestNumber).IsUnique();

            builder.HasOne<BusinessParty>()
                .WithMany()
                .HasForeignKey(entry => entry.CustomerPartyId)
                .OnDelete(DeleteBehavior.Restrict);
        });
    }

    private static void ConfigureAudit(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AuditEvent>(builder =>
        {
            builder.ToTable("audit_evt");
            builder.HasKey(auditEvent => auditEvent.Id);
            builder.Property(auditEvent => auditEvent.Id).HasColumnName("audit_evt_id");
            builder.Property(auditEvent => auditEvent.ModuleCode).HasColumnName("module_code").HasMaxLength(30).IsRequired();
            builder.Property(auditEvent => auditEvent.EntityName).HasColumnName("entity_name").HasMaxLength(60).IsRequired();
            builder.Property(auditEvent => auditEvent.EntityId).HasColumnName("entity_id");
            builder.Property(auditEvent => auditEvent.ActionCode).HasColumnName("action_code").HasMaxLength(30).IsRequired();
            builder.Property(auditEvent => auditEvent.ActorUserId).HasColumnName("actor_user_id");
            builder.Property(auditEvent => auditEvent.BranchId).HasColumnName("branch_id");
            builder.Property(auditEvent => auditEvent.OldValue).HasColumnName("old_value");
            builder.Property(auditEvent => auditEvent.NewValue).HasColumnName("new_value");
            builder.Property(auditEvent => auditEvent.OccurredAtUtc).HasColumnName("occurred_at");
            builder.Ignore(auditEvent => auditEvent.CreatedAtUtc);
            builder.Ignore(auditEvent => auditEvent.CreatedByUserId);
            builder.Ignore(auditEvent => auditEvent.UpdatedAtUtc);
            builder.Ignore(auditEvent => auditEvent.UpdatedByUserId);

            builder.HasData(new
            {
                Id = 1L,
                ModuleCode = "PROCUREMENT",
                EntityName = "PURCHASE_REQUISITION",
                EntityId = 1L,
                ActionCode = "SUBMITTED",
                ActorUserId = 1L,
                BranchId = 1L,
                OldValue = "{}",
                NewValue = "{\"status\":\"SUBMITTED\"}",
                OccurredAtUtc = SeedSubmittedAtUtc
            });
        });
    }

    private static void ConfigureDocuments(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<DocumentLink>(builder =>
        {
            builder.ToTable("doc_link");
            builder.HasKey(documentLink => documentLink.Id);
            builder.Property(documentLink => documentLink.Id).HasColumnName("doc_link_id");
            builder.Property(documentLink => documentLink.ModuleCode).HasColumnName("module_code").HasMaxLength(30).IsRequired();
            builder.Property(documentLink => documentLink.EntityName).HasColumnName("entity_name").HasMaxLength(60).IsRequired();
            builder.Property(documentLink => documentLink.EntityId).HasColumnName("entity_id");
            builder.Property(documentLink => documentLink.DocumentType).HasColumnName("doc_type").HasMaxLength(30).IsRequired();
            builder.Property(documentLink => documentLink.AttachmentCategoryCode).HasColumnName("attach_cat_code").HasMaxLength(40).IsRequired();
            builder.Property(documentLink => documentLink.FileName).HasColumnName("file_name").HasMaxLength(255).IsRequired();
            builder.Property(documentLink => documentLink.StorageReference).HasColumnName("storage_ref").HasMaxLength(500).IsRequired();
            builder.Property(documentLink => documentLink.StorageProviderCode).HasColumnName("storage_provider_code").HasMaxLength(40).IsRequired();
            builder.Property(documentLink => documentLink.ContentType).HasColumnName("content_type").HasMaxLength(100);
            builder.Property(documentLink => documentLink.FileSizeBytes).HasColumnName("file_size_bytes");
            builder.Property(documentLink => documentLink.ChecksumText).HasColumnName("checksum_txt").HasMaxLength(128);
            builder.Property(documentLink => documentLink.LifecycleStatusCode).HasColumnName("lifecycle_status_code").HasMaxLength(30).IsRequired();
            builder.Property(documentLink => documentLink.VersionNumber).HasColumnName("version_no");
            builder.Property(documentLink => documentLink.SupersededByDocumentLinkId).HasColumnName("superseded_by_doc_link_id");
            builder.Property(documentLink => documentLink.RetentionUntilUtc).HasColumnName("retention_until_utc");
            builder.Property(documentLink => documentLink.ArchivedAtUtc).HasColumnName("archived_at_utc");
            builder.Property(documentLink => documentLink.ArchivedByUserId).HasColumnName("archived_by_user_id");
            builder.Property(documentLink => documentLink.LifecycleNotesText).HasColumnName("lifecycle_notes_txt").HasMaxLength(1000);
            builder.Property(documentLink => documentLink.UploadedByUserId).HasColumnName("uploaded_by");
            builder.Property(documentLink => documentLink.UploadedAtUtc).HasColumnName("uploaded_at");
            builder.Ignore(documentLink => documentLink.CreatedAtUtc);
            builder.Ignore(documentLink => documentLink.CreatedByUserId);
            builder.Ignore(documentLink => documentLink.UpdatedAtUtc);
            builder.Ignore(documentLink => documentLink.UpdatedByUserId);

            builder.HasData(new
            {
                Id = 1L,
                ModuleCode = "PROCUREMENT",
                EntityName = "PURCHASE_REQUISITION",
                EntityId = 1L,
                DocumentType = "SUPPORTING_ATTACHMENT",
                AttachmentCategoryCode = "GENERAL",
                FileName = "pr-000001-attachment.pdf",
                StorageReference = "dev/procurement/pr-000001/supporting-attachment.pdf",
                StorageProviderCode = "MANAGED_STORAGE",
                ContentType = "application/pdf",
                FileSizeBytes = 182944,
                ChecksumText = (string?)null,
                LifecycleStatusCode = "ACTIVE",
                VersionNumber = 1,
                SupersededByDocumentLinkId = (long?)null,
                RetentionUntilUtc = (DateTime?)null,
                ArchivedAtUtc = (DateTime?)null,
                ArchivedByUserId = (long?)null,
                LifecycleNotesText = (string?)null,
                UploadedByUserId = 1L,
                UploadedAtUtc = SeedSubmittedAtUtc
            });
        });
    }

    private static void ConfigureMasterDataGovernance(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ReferenceDataEntry>(builder =>
        {
            builder.ToTable("ref_data_entry");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("ref_data_entry_id");
            builder.Property(entry => entry.EntryCode).HasColumnName("entry_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.ReferenceTypeCode).HasColumnName("ref_type_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.ReferenceCode).HasColumnName("ref_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.ReferenceName).HasColumnName("ref_name").HasMaxLength(200).IsRequired();
            builder.Property(entry => entry.LocalizedName).HasColumnName("localized_name").HasMaxLength(200);
            builder.Property(entry => entry.DescriptionText).HasColumnName("description_txt").HasMaxLength(1000);
            builder.Property(entry => entry.AttributesJson).HasColumnName("attributes_json").HasMaxLength(4000);
            builder.Property(entry => entry.StatusId).HasColumnName("status_id");
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.EffectiveFrom).HasColumnName("effective_from");
            builder.Property(entry => entry.EffectiveTo).HasColumnName("effective_to");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Ignore(entry => entry.CreatedAtUtc);
            builder.Ignore(entry => entry.CreatedByUserId);
            builder.Ignore(entry => entry.UpdatedAtUtc);
            builder.Ignore(entry => entry.UpdatedByUserId);

            builder.HasData(
                new
                {
                    Id = 1L,
                    EntryCode = "REF-000001",
                    ReferenceTypeCode = "CURRENCY",
                    ReferenceCode = "EGP",
                    ReferenceName = "Egyptian Pound",
                    LocalizedName = "الجنيه المصري",
                    DescriptionText = "Release 1 base functional currency.",
                    AttributesJson = "{\"symbol\":\"EGP\",\"decimalPlaces\":2,\"isBaseCurrency\":true,\"baseCurrencyCode\":\"EGP\",\"rateToBase\":1}",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    EffectiveFrom = new DateOnly(2026, 1, 1),
                    EffectiveTo = (DateOnly?)null,
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc,
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc,
                    ActivatedByUserId = 2L
                },
                new
                {
                    Id = 2L,
                    EntryCode = "REF-000002",
                    ReferenceTypeCode = "CURRENCY",
                    ReferenceCode = "USD",
                    ReferenceName = "US Dollar",
                    LocalizedName = "الدولار الأمريكي",
                    DescriptionText = "Release 1 secondary operating currency.",
                    AttributesJson = "{\"symbol\":\"USD\",\"decimalPlaces\":2,\"baseCurrencyCode\":\"EGP\",\"rateToBase\":49.50}",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    EffectiveFrom = new DateOnly(2026, 1, 1),
                    EffectiveTo = (DateOnly?)null,
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc,
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc,
                    ActivatedByUserId = 2L
                },
                new
                {
                    Id = 3L,
                    EntryCode = "REF-000003",
                    ReferenceTypeCode = "UNIT_OF_MEASURE",
                    ReferenceCode = "EA",
                    ReferenceName = "Each",
                    LocalizedName = "قطعة",
                    DescriptionText = "Default stock and sales UOM.",
                    AttributesJson = "{\"precision\":0}",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    EffectiveFrom = new DateOnly(2026, 1, 1),
                    EffectiveTo = (DateOnly?)null,
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc,
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc,
                    ActivatedByUserId = 2L
                },
                new
                {
                    Id = 4L,
                    EntryCode = "REF-000004",
                    ReferenceTypeCode = "TAX_CODE",
                    ReferenceCode = "VAT14",
                    ReferenceName = "VAT 14 Percent",
                    LocalizedName = "ضريبة قيمة مضافة 14%",
                    DescriptionText = "Standard taxable sales and purchase code.",
                    AttributesJson = "{\"ratePercent\":14,\"etaTaxCode\":\"T1\"}",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    EffectiveFrom = new DateOnly(2026, 1, 1),
                    EffectiveTo = (DateOnly?)null,
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc,
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc,
                    ActivatedByUserId = 2L
                },
                new
                {
                    Id = 5L,
                    EntryCode = "REF-000005",
                    ReferenceTypeCode = "WAREHOUSE",
                    ReferenceCode = "MAIN_WH",
                    ReferenceName = "Main Warehouse",
                    LocalizedName = "المخزن الرئيسي",
                    DescriptionText = "Primary receiving and dispatch warehouse.",
                    AttributesJson = "{\"branchId\":1,\"dispatchEnabled\":true,\"locationModel\":\"ZONE_BIN\"}",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    EffectiveFrom = new DateOnly(2026, 1, 1),
                    EffectiveTo = (DateOnly?)null,
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc,
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc,
                    ActivatedByUserId = 2L
                });
        });
    }

    private static void ConfigureIslamicFinanceGovernance(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<IslamicFinancePartnerLender>(builder =>
        {
            builder.ToTable("if_partner_lender");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_partner_lender_id");
            builder.Property(entry => entry.PartnerLenderPartyId).HasColumnName("partner_lender_party_id");
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.DefaultCurrencyCode).HasColumnName("default_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.SupportsMurabaha).HasColumnName("supports_murabaha");
            builder.Property(entry => entry.SupportsReceivablesFinance).HasColumnName("supports_receivables_finance");
            builder.Property(entry => entry.SupportsTawarruq).HasColumnName("supports_tawarruq");
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("workflow_instance_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.PartnerLenderPartyId).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceProductProfile>(builder =>
        {
            builder.ToTable("if_product_profile");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_product_profile_id");
            builder.Property(entry => entry.ProductType).HasColumnName("product_type").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.ProductCode).HasColumnName("product_code").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.ProductName).HasColumnName("product_name").HasMaxLength(200).IsRequired();
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.RequiresShariahReview).HasColumnName("requires_shariah_review");
            builder.Property(entry => entry.AllowsPartnerFunding).HasColumnName("allows_partner_funding");
            builder.Property(entry => entry.AllowsCashLineFunding).HasColumnName("allows_cashline_funding");
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("workflow_instance_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.ProductCode).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceFacility>(builder =>
        {
            builder.ToTable("if_facility");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_facility_id");
            builder.Property(entry => entry.PartnerLenderId).HasColumnName("partner_lender_id");
            builder.Property(entry => entry.CustomerPartyId).HasColumnName("customer_party_id");
            builder.Property(entry => entry.ProductProfileId).HasColumnName("product_profile_id");
            builder.Property(entry => entry.FacilityNumber).HasColumnName("facility_no").HasMaxLength(80).IsRequired();
            builder.Property(entry => entry.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.ApprovedLimitAmount).HasColumnName("approved_limit_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.UtilizedAmount).HasColumnName("utilized_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("workflow_instance_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.FacilityNumber).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceContractTemplate>(builder =>
        {
            builder.ToTable("if_contract_template");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_contract_template_id");
            builder.Property(entry => entry.ProductProfileId).HasColumnName("product_profile_id");
            builder.Property(entry => entry.TemplateCode).HasColumnName("template_code").HasMaxLength(80).IsRequired();
            builder.Property(entry => entry.TemplateName).HasColumnName("template_name").HasMaxLength(200).IsRequired();
            builder.Property(entry => entry.LanguageCode).HasColumnName("language_code").HasMaxLength(20).IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("workflow_instance_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.TemplateCode).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceRequest>(builder =>
        {
            builder.ToTable("if_financing_request");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_financing_request_id");
            builder.Property(entry => entry.RequestNumber).HasColumnName("request_no").HasMaxLength(80).IsRequired();
            builder.Property(entry => entry.CustomerPartyId).HasColumnName("customer_party_id");
            builder.Property(entry => entry.ApplicantPartyId).HasColumnName("applicant_party_id");
            builder.Property(entry => entry.ApplicantPartyTypeCode).HasColumnName("applicant_party_type_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.ProductProfileId).HasColumnName("product_profile_id");
            builder.Property(entry => entry.FacilityId).HasColumnName("facility_id");
            builder.Property(entry => entry.FundingSourceMode).HasColumnName("funding_source_mode").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.SourceDocumentType).HasColumnName("source_document_type").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.SourceDocumentId).HasColumnName("source_document_id");
            builder.Property(entry => entry.TransactionCurrencyCode).HasColumnName("transaction_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.RequestedAmount).HasColumnName("requested_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("workflow_instance_id");
            builder.Property(entry => entry.ShariahReviewCaseId).HasColumnName("shariah_review_case_id");
            builder.Property(entry => entry.AssignedPartnerLenderId).HasColumnName("assigned_partner_lender_id");
            builder.Property(entry => entry.SelectedFinancingDecisionId).HasColumnName("selected_financing_decision_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ReturnedAtUtc).HasColumnName("returned_at");
            builder.Property(entry => entry.ReturnedByUserId).HasColumnName("returned_by");
            builder.Property(entry => entry.RejectedAtUtc).HasColumnName("rejected_at");
            builder.Property(entry => entry.RejectedByUserId).HasColumnName("rejected_by");
            builder.Property(entry => entry.AssignedPartnerLenderAtUtc).HasColumnName("partner_lender_assigned_at");
            builder.Property(entry => entry.AssignedPartnerLenderByUserId).HasColumnName("partner_lender_assigned_by");
            builder.Property(entry => entry.SelectedOfferAtUtc).HasColumnName("selected_offer_at");
            builder.Property(entry => entry.SelectedOfferByUserId).HasColumnName("selected_offer_by");
            builder.Property(entry => entry.ShariahReviewAttachedAtUtc).HasColumnName("shariah_review_attached_at");
            builder.Property(entry => entry.ShariahReviewAttachedByUserId).HasColumnName("shariah_review_attached_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.RequestNumber).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceDecision>(builder =>
        {
            builder.ToTable("if_financing_decision");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_financing_decision_id");
            builder.Property(entry => entry.FinancingRequestId).HasColumnName("financing_request_id");
            builder.Property(entry => entry.DecisionCode).HasColumnName("decision_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.DecisionNotes).HasColumnName("decision_notes").HasMaxLength(2000);
            builder.Property(entry => entry.DecidingPartyId).HasColumnName("deciding_party_id");
            builder.Property(entry => entry.PartnerLenderId).HasColumnName("partner_lender_id");
            builder.Property(entry => entry.OfferProductTypeCode).HasColumnName("offer_product_type_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.OfferFundingSourceMode).HasColumnName("offer_funding_source_mode").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.OfferCurrencyCode).HasColumnName("offer_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.OfferedAmount).HasColumnName("offered_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.TenorMonths).HasColumnName("tenor_months");
            builder.Property(entry => entry.ProfitRatePercent).HasColumnName("profit_rate_pct").HasPrecision(9, 4);
            builder.Property(entry => entry.ProcessingFeeAmount).HasColumnName("processing_fee_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.SecurityRequirementText).HasColumnName("security_requirement_txt").HasMaxLength(1000);
            builder.Property(entry => entry.OfferRank).HasColumnName("offer_rank");
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ReturnedAtUtc).HasColumnName("returned_at");
            builder.Property(entry => entry.ReturnedByUserId).HasColumnName("returned_by");
            builder.Property(entry => entry.RejectedAtUtc).HasColumnName("rejected_at");
            builder.Property(entry => entry.RejectedByUserId).HasColumnName("rejected_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<IslamicFinanceReceivablesCase>(builder =>
        {
            builder.ToTable("if_receivables_case");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_receivables_case_id");
            builder.Property(entry => entry.CaseNumber).HasColumnName("case_no").HasMaxLength(80).IsRequired();
            builder.Property(entry => entry.FinancingRequestId).HasColumnName("financing_request_id");
            builder.Property(entry => entry.CustomerPartyId).HasColumnName("customer_party_id");
            builder.Property(entry => entry.PartnerLenderId).HasColumnName("partner_lender_id");
            builder.Property(entry => entry.FacilityId).HasColumnName("facility_id");
            builder.Property(entry => entry.ProductProfileId).HasColumnName("product_profile_id");
            builder.Property(entry => entry.TransactionCurrencyCode).HasColumnName("transaction_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.TotalReceivableAmount).HasColumnName("total_receivable_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.FinancedAmount).HasColumnName("financed_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.AdvanceRatePercent).HasColumnName("advance_rate_percent").HasPrecision(9, 4);
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("workflow_instance_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.CaseNumber).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceReceivablesCaseLine>(builder =>
        {
            builder.ToTable("if_receivables_case_ln");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_receivables_case_ln_id");
            builder.Property(entry => entry.IslamicFinanceReceivablesCaseId).HasColumnName("if_receivables_case_id");
            builder.Property(entry => entry.AccountsReceivableInvoiceId).HasColumnName("ar_invoice_id");
            builder.Property(entry => entry.ReceivableAmount).HasColumnName("receivable_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.FinancedAmount).HasColumnName("financed_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<IslamicFinanceMurabahaCase>(builder =>
        {
            builder.ToTable("if_murabaha_case");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_murabaha_case_id");
            builder.Property(entry => entry.CaseNumber).HasColumnName("case_no").HasMaxLength(80).IsRequired();
            builder.Property(entry => entry.FinancingRequestId).HasColumnName("financing_request_id");
            builder.Property(entry => entry.CustomerPartyId).HasColumnName("customer_party_id");
            builder.Property(entry => entry.PartnerLenderId).HasColumnName("partner_lender_id");
            builder.Property(entry => entry.SupplierPartyId).HasColumnName("supplier_party_id");
            builder.Property(entry => entry.ProductProfileId).HasColumnName("product_profile_id");
            builder.Property(entry => entry.ContractTemplateId).HasColumnName("contract_template_id");
            builder.Property(entry => entry.TransactionCurrencyCode).HasColumnName("transaction_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.PurchaseCostAmount).HasColumnName("purchase_cost_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.ProfitAmount).HasColumnName("profit_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.SalePriceAmount).HasColumnName("sale_price_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("workflow_instance_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.CaseNumber).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceMurabahaAsset>(builder =>
        {
            builder.ToTable("if_murabaha_asset");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_murabaha_asset_id");
            builder.Property(entry => entry.MurabahaCaseId).HasColumnName("murabaha_case_id");
            builder.Property(entry => entry.AssetDescription).HasColumnName("asset_description").HasMaxLength(500).IsRequired();
            builder.Property(entry => entry.SupplierPartyId).HasColumnName("supplier_party_id");
            builder.Property(entry => entry.PurchaseReferenceNumber).HasColumnName("purchase_reference_no").HasMaxLength(80);
            builder.Property(entry => entry.PurchaseCostAmount).HasColumnName("purchase_cost_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => new { entry.MurabahaCaseId, entry.PurchaseReferenceNumber }).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceMurabahaDisbursement>(builder =>
        {
            builder.ToTable("if_disbursement");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_disbursement_id");
            builder.Property(entry => entry.DisbursementNumber).HasColumnName("disbursement_no").HasMaxLength(80).IsRequired();
            builder.Property(entry => entry.MurabahaCaseId).HasColumnName("murabaha_case_id");
            builder.Property(entry => entry.CustomerPartyId).HasColumnName("customer_party_id");
            builder.Property(entry => entry.PartnerLenderId).HasColumnName("partner_lender_id");
            builder.Property(entry => entry.SupplierPartyId).HasColumnName("supplier_party_id");
            builder.Property(entry => entry.FundingSourceMode).HasColumnName("funding_source_mode").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.TargetType).HasColumnName("target_type").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.TransactionCurrencyCode).HasColumnName("transaction_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.InstructedAmount).HasColumnName("instructed_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.ExecutedAmount).HasColumnName("executed_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.PlannedExecutionDate).HasColumnName("planned_execution_date");
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("workflow_instance_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ExecutedAtUtc).HasColumnName("executed_at");
            builder.Property(entry => entry.ExecutedByUserId).HasColumnName("executed_by");
            builder.Property(entry => entry.ExecutionReferenceNumber).HasColumnName("execution_reference_no").HasMaxLength(80);
            builder.Property(entry => entry.ExecutionNotes).HasColumnName("execution_notes").HasMaxLength(2000);
            builder.Property(entry => entry.SuspendedAtUtc).HasColumnName("suspended_at");
            builder.Property(entry => entry.SuspendedByUserId).HasColumnName("suspended_by");
            builder.Property(entry => entry.SuspensionReasonCode).HasColumnName("suspension_reason_code").HasMaxLength(40);
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.DisbursementNumber).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceSettlementHeader>(builder =>
        {
            builder.ToTable("if_settlement_hdr");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_settlement_hdr_id");
            builder.Property(entry => entry.SettlementNumber).HasColumnName("settlement_no").HasMaxLength(80).IsRequired();
            builder.Property(entry => entry.MurabahaCaseId).HasColumnName("murabaha_case_id");
            builder.Property(entry => entry.FinancingRequestId).HasColumnName("financing_request_id");
            builder.Property(entry => entry.PartnerLenderId).HasColumnName("partner_lender_id");
            builder.Property(entry => entry.FundingSourceMode).HasColumnName("funding_source_mode").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.SettlementDate).HasColumnName("settlement_date");
            builder.Property(entry => entry.SettlementCurrencyCode).HasColumnName("settlement_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.TotalSettledAmount).HasColumnName("total_settled_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("workflow_instance_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ClosedAtUtc).HasColumnName("closed_at");
            builder.Property(entry => entry.ClosedByUserId).HasColumnName("closed_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.SettlementNumber).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceSettlementLine>(builder =>
        {
            builder.ToTable("if_settlement_ln");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_settlement_ln_id");
            builder.Property(entry => entry.IslamicFinanceSettlementHeaderId).HasColumnName("if_settlement_hdr_id");
            builder.Property(entry => entry.MurabahaDisbursementId).HasColumnName("murabaha_disbursement_id");
            builder.Property(entry => entry.SettledAmount).HasColumnName("settled_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.MurabahaDisbursementId).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceProfitSchedule>(builder =>
        {
            builder.ToTable("if_profit_schedule");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_profit_schedule_id");
            builder.Property(entry => entry.MurabahaCaseId).HasColumnName("murabaha_case_id");
            builder.Property(entry => entry.InstallmentNumber).HasColumnName("installment_no");
            builder.Property(entry => entry.DueDate).HasColumnName("due_date");
            builder.Property(entry => entry.PrincipalAmount).HasColumnName("principal_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.ProfitAmount).HasColumnName("profit_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.InstallmentAmount).HasColumnName("installment_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.OutstandingBalanceAmount).HasColumnName("outstanding_balance_amount").HasPrecision(18, 2);
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => new { entry.MurabahaCaseId, entry.InstallmentNumber }).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceAccountingHook>(builder =>
        {
            builder.ToTable("if_accounting_hook");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_accounting_hook_id");
            builder.Property(entry => entry.SourceEntityType).HasColumnName("source_entity_type").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.SourceEntityId).HasColumnName("source_entity_id");
            builder.Property(entry => entry.FundingSourceMode).HasColumnName("funding_source_mode").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.ProductType).HasColumnName("product_type").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.CustomerPartyId).HasColumnName("customer_party_id");
            builder.Property(entry => entry.PartnerLenderId).HasColumnName("partner_lender_id");
            builder.Property(entry => entry.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(entry => entry.PostingStatusCode).HasColumnName("posting_status").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => new { entry.SourceEntityType, entry.SourceEntityId }).IsUnique();
        });

        modelBuilder.Entity<IslamicFinanceShariahReviewCase>(builder =>
        {
            builder.ToTable("if_shariah_review_case");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("if_shariah_review_case_id");
            builder.Property(entry => entry.ReviewCaseNumber).HasColumnName("review_case_no").HasMaxLength(80).IsRequired();
            builder.Property(entry => entry.ProductProfileId).HasColumnName("product_profile_id");
            builder.Property(entry => entry.FinancingRequestId).HasColumnName("financing_request_id");
            builder.Property(entry => entry.ReviewReasonCode).HasColumnName("review_reason_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.ReviewOutcomeCode).HasColumnName("review_outcome_code").HasMaxLength(30);
            builder.Property(entry => entry.ReviewNotes).HasColumnName("review_notes").HasMaxLength(2000);
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.WorkflowInstanceId).HasColumnName("workflow_instance_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ReviewedAtUtc).HasColumnName("reviewed_at");
            builder.Property(entry => entry.ReviewedByUserId).HasColumnName("reviewed_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => entry.ReviewCaseNumber).IsUnique();
        });
    }

    private static void ConfigureLocalization(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<LocalizationResource>(builder =>
        {
            builder.ToTable("loc_resource");
            builder.HasKey(resource => resource.Id);
            builder.Property(resource => resource.Id).HasColumnName("loc_resource_id");
            builder.Property(resource => resource.ResourceSetCode).HasColumnName("resource_set_code").HasMaxLength(60).IsRequired();
            builder.Property(resource => resource.CultureCode).HasColumnName("culture_code").HasMaxLength(20).IsRequired();
            builder.Property(resource => resource.ResourceKey).HasColumnName("resource_key").HasMaxLength(120).IsRequired();
            builder.Property(resource => resource.ResourceValue).HasColumnName("resource_value").HasMaxLength(4000).IsRequired();
            builder.Property(resource => resource.TextDirectionCode).HasColumnName("text_direction_code").HasMaxLength(3).IsRequired();
            builder.Property(resource => resource.IsActive).HasColumnName("is_active");
            builder.Property(resource => resource.SortOrder).HasColumnName("sort_order");

            builder.HasData(
                CreateLocalizationSeed(1L, LocalizationCultureCode.EnglishUnitedStates, 10, "app.title", "CashLine ERP Admin Setup"),
                CreateLocalizationSeed(2L, LocalizationCultureCode.EnglishUnitedStates, 20, "app.description", "Internal admin setup screens for governed master and reference data in CashLine ERP."),
                CreateLocalizationSeed(3L, LocalizationCultureCode.EnglishUnitedStates, 30, "sidebar.kicker", "CashLine ERP"),
                CreateLocalizationSeed(4L, LocalizationCultureCode.EnglishUnitedStates, 40, "sidebar.title", "Admin Setup"),
                CreateLocalizationSeed(5L, LocalizationCultureCode.EnglishUnitedStates, 50, "sidebar.description", "Governed master/reference data workspace for internal operations teams."),
                CreateLocalizationSeed(6L, LocalizationCultureCode.EnglishUnitedStates, 60, "nav.overview", "Overview"),
                CreateLocalizationSeed(7L, LocalizationCultureCode.EnglishUnitedStates, 70, "nav.referenceSets", "Reference Sets"),
                CreateLocalizationSeed(8L, LocalizationCultureCode.EnglishUnitedStates, 80, "nav.createEntry", "Create Entry"),
                CreateLocalizationSeed(9L, LocalizationCultureCode.EnglishUnitedStates, 90, "nav.approvalPath", "Approval Path"),
                CreateLocalizationSeed(10L, LocalizationCultureCode.EnglishUnitedStates, 100, "governance.label", "Governance Model"),
                CreateLocalizationSeed(11L, LocalizationCultureCode.EnglishUnitedStates, 110, "governance.value", "Draft to submitted to approved to active"),
                CreateLocalizationSeed(12L, LocalizationCultureCode.EnglishUnitedStates, 120, "hero.eyebrow", "Internal Setup Workspace"),
                CreateLocalizationSeed(13L, LocalizationCultureCode.EnglishUnitedStates, 130, "hero.title", "Reference data with maker-checker control and activation discipline"),
                CreateLocalizationSeed(14L, LocalizationCultureCode.EnglishUnitedStates, 140, "hero.description", "This screen pack sits on top of the admin setup APIs and gives internal operators one place to manage currencies, UOMs, tax codes, and warehouses under governed approval."),
                CreateLocalizationSeed(15L, LocalizationCultureCode.EnglishUnitedStates, 150, "overview.totalEntries", "Total entries"),
                CreateLocalizationSeed(16L, LocalizationCultureCode.EnglishUnitedStates, 160, "overview.activeEntries", "Active entries"),
                CreateLocalizationSeed(17L, LocalizationCultureCode.EnglishUnitedStates, 170, "overview.submittedEntries", "Submitted entries"),
                CreateLocalizationSeed(18L, LocalizationCultureCode.EnglishUnitedStates, 180, "overview.currencies", "Currencies"),
                CreateLocalizationSeed(19L, LocalizationCultureCode.EnglishUnitedStates, 190, "overview.uoms", "UOMs"),
                CreateLocalizationSeed(20L, LocalizationCultureCode.EnglishUnitedStates, 200, "overview.taxCodes", "Tax codes"),
                CreateLocalizationSeed(21L, LocalizationCultureCode.EnglishUnitedStates, 210, "overview.warehouses", "Warehouses"),
                CreateLocalizationSeed(22L, LocalizationCultureCode.EnglishUnitedStates, 220, "types.eyebrow", "Reference Sets"),
                CreateLocalizationSeed(23L, LocalizationCultureCode.EnglishUnitedStates, 230, "types.title", "Operational setup families"),
                CreateLocalizationSeed(24L, LocalizationCultureCode.EnglishUnitedStates, 240, "filters.referenceType", "Reference type"),
                CreateLocalizationSeed(25L, LocalizationCultureCode.EnglishUnitedStates, 250, "filters.activeOnly", "Active only"),
                CreateLocalizationSeed(26L, LocalizationCultureCode.EnglishUnitedStates, 260, "filters.all", "All"),
                CreateLocalizationSeed(27L, LocalizationCultureCode.EnglishUnitedStates, 270, "filters.currency", "Currency"),
                CreateLocalizationSeed(28L, LocalizationCultureCode.EnglishUnitedStates, 280, "filters.uom", "Unit Of Measure"),
                CreateLocalizationSeed(29L, LocalizationCultureCode.EnglishUnitedStates, 290, "filters.taxCode", "Tax Code"),
                CreateLocalizationSeed(30L, LocalizationCultureCode.EnglishUnitedStates, 300, "filters.warehouse", "Warehouse"),
                CreateLocalizationSeed(31L, LocalizationCultureCode.EnglishUnitedStates, 310, "entry.referenceEntry", "Entry"),
                CreateLocalizationSeed(32L, LocalizationCultureCode.EnglishUnitedStates, 320, "entry.localized", "Localized"),
                CreateLocalizationSeed(33L, LocalizationCultureCode.EnglishUnitedStates, 330, "entry.attributes", "Attributes"),
                CreateLocalizationSeed(34L, LocalizationCultureCode.EnglishUnitedStates, 340, "entry.notSet", "Not set"),
                CreateLocalizationSeed(35L, LocalizationCultureCode.EnglishUnitedStates, 350, "entry.noDescription", "No description provided."),
                CreateLocalizationSeed(36L, LocalizationCultureCode.EnglishUnitedStates, 360, "entry.active", "ACTIVE"),
                CreateLocalizationSeed(37L, LocalizationCultureCode.EnglishUnitedStates, 370, "form.eyebrow", "Create Entry"),
                CreateLocalizationSeed(38L, LocalizationCultureCode.EnglishUnitedStates, 380, "form.title", "Draft a governed setup record"),
                CreateLocalizationSeed(39L, LocalizationCultureCode.EnglishUnitedStates, 390, "form.referenceType", "Reference type"),
                CreateLocalizationSeed(40L, LocalizationCultureCode.EnglishUnitedStates, 400, "form.referenceCode", "Reference code"),
                CreateLocalizationSeed(41L, LocalizationCultureCode.EnglishUnitedStates, 410, "form.referenceName", "Reference name"),
                CreateLocalizationSeed(42L, LocalizationCultureCode.EnglishUnitedStates, 420, "form.localizedName", "Localized name"),
                CreateLocalizationSeed(43L, LocalizationCultureCode.EnglishUnitedStates, 430, "form.effectiveFrom", "Effective from"),
                CreateLocalizationSeed(44L, LocalizationCultureCode.EnglishUnitedStates, 440, "form.effectiveTo", "Effective to"),
                CreateLocalizationSeed(45L, LocalizationCultureCode.EnglishUnitedStates, 450, "form.description", "Description"),
                CreateLocalizationSeed(46L, LocalizationCultureCode.EnglishUnitedStates, 460, "form.attributesJson", "Attributes JSON"),
                CreateLocalizationSeed(47L, LocalizationCultureCode.EnglishUnitedStates, 470, "form.submit", "Create Draft"),
                CreateLocalizationSeed(48L, LocalizationCultureCode.EnglishUnitedStates, 480, "form.status.ready", "Ready"),
                CreateLocalizationSeed(49L, LocalizationCultureCode.EnglishUnitedStates, 490, "form.status.creating", "Creating draft..."),
                CreateLocalizationSeed(50L, LocalizationCultureCode.EnglishUnitedStates, 500, "form.status.created", "Draft created"),
                CreateLocalizationSeed(51L, LocalizationCultureCode.EnglishUnitedStates, 510, "form.status.apiUnavailable", "API not reachable here. Layout is ready for internal hosting."),
                CreateLocalizationSeed(52L, LocalizationCultureCode.EnglishUnitedStates, 520, "form.placeholder.referenceCode", "VAT14"),
                CreateLocalizationSeed(53L, LocalizationCultureCode.EnglishUnitedStates, 530, "form.placeholder.referenceName", "VAT 14 Percent"),
                CreateLocalizationSeed(54L, LocalizationCultureCode.EnglishUnitedStates, 540, "form.placeholder.localizedName", "Arabic localized name"),
                CreateLocalizationSeed(55L, LocalizationCultureCode.EnglishUnitedStates, 550, "form.placeholder.description", "Operational notes"),
                CreateLocalizationSeed(56L, LocalizationCultureCode.EnglishUnitedStates, 560, "form.placeholder.attributesJson", "{\"branchId\":1,\"dispatchEnabled\":true}"),
                CreateLocalizationSeed(57L, LocalizationCultureCode.EnglishUnitedStates, 570, "queue.eyebrow", "Approval Path"),
                CreateLocalizationSeed(58L, LocalizationCultureCode.EnglishUnitedStates, 580, "queue.title", "What governance looks like in practice"),
                CreateLocalizationSeed(59L, LocalizationCultureCode.EnglishUnitedStates, 590, "queue.step1.title", "1. Draft"),
                CreateLocalizationSeed(60L, LocalizationCultureCode.EnglishUnitedStates, 600, "queue.step1.body", "Operations or admin users draft a new reference record with clear attributes."),
                CreateLocalizationSeed(61L, LocalizationCultureCode.EnglishUnitedStates, 610, "queue.step2.title", "2. Submitted"),
                CreateLocalizationSeed(62L, LocalizationCultureCode.EnglishUnitedStates, 620, "queue.step2.body", "The entry moves into the internal approval queue under module code `MASTER_DATA`."),
                CreateLocalizationSeed(63L, LocalizationCultureCode.EnglishUnitedStates, 630, "queue.step3.title", "3. Approved"),
                CreateLocalizationSeed(64L, LocalizationCultureCode.EnglishUnitedStates, 640, "queue.step3.body", "A checker reviews the business meaning and setup impact without self-approval."),
                CreateLocalizationSeed(65L, LocalizationCultureCode.EnglishUnitedStates, 650, "queue.step4.title", "4. Active"),
                CreateLocalizationSeed(66L, LocalizationCultureCode.EnglishUnitedStates, 660, "queue.step4.body", "Activation makes the setup record operational while blocking duplicate active codes."),
                CreateLocalizationSeed(67L, LocalizationCultureCode.EnglishUnitedStates, 670, "culture.english", "English"),
                CreateLocalizationSeed(68L, LocalizationCultureCode.EnglishUnitedStates, 680, "culture.arabic", "Arabic"),
                CreateLocalizationSeed(69L, LocalizationCultureCode.ArabicEgypt, 10, "app.title", "إعدادات إدارة كاش لاين"),
                CreateLocalizationSeed(70L, LocalizationCultureCode.ArabicEgypt, 20, "app.description", "شاشات داخلية لإدارة البيانات المرجعية والأساسية المحكومة في كاش لاين."),
                CreateLocalizationSeed(71L, LocalizationCultureCode.ArabicEgypt, 30, "sidebar.kicker", "كاش لاين ERP"),
                CreateLocalizationSeed(72L, LocalizationCultureCode.ArabicEgypt, 40, "sidebar.title", "إعدادات الإدارة"),
                CreateLocalizationSeed(73L, LocalizationCultureCode.ArabicEgypt, 50, "sidebar.description", "مساحة عمل محكومة للبيانات المرجعية والأساسية لفرق التشغيل الداخلية."),
                CreateLocalizationSeed(74L, LocalizationCultureCode.ArabicEgypt, 60, "nav.overview", "نظرة عامة"),
                CreateLocalizationSeed(75L, LocalizationCultureCode.ArabicEgypt, 70, "nav.referenceSets", "المجموعات المرجعية"),
                CreateLocalizationSeed(76L, LocalizationCultureCode.ArabicEgypt, 80, "nav.createEntry", "إنشاء سجل"),
                CreateLocalizationSeed(77L, LocalizationCultureCode.ArabicEgypt, 90, "nav.approvalPath", "مسار الاعتماد"),
                CreateLocalizationSeed(78L, LocalizationCultureCode.ArabicEgypt, 100, "governance.label", "نموذج الحوكمة"),
                CreateLocalizationSeed(79L, LocalizationCultureCode.ArabicEgypt, 110, "governance.value", "مسودة ثم مرسل ثم معتمد ثم فعال"),
                CreateLocalizationSeed(80L, LocalizationCultureCode.ArabicEgypt, 120, "hero.eyebrow", "مساحة إعداد داخلية"),
                CreateLocalizationSeed(81L, LocalizationCultureCode.ArabicEgypt, 130, "hero.title", "بيانات مرجعية مع رقابة منفذ ومراجع وانضباط في التفعيل"),
                CreateLocalizationSeed(82L, LocalizationCultureCode.ArabicEgypt, 140, "hero.description", "يعتمد هذا النموذج على واجهات إعداد الإدارة ويمنح فرق التشغيل مكانا واحدا لإدارة العملات ووحدات القياس والضرائب والمخازن تحت اعتماد محكوم."),
                CreateLocalizationSeed(83L, LocalizationCultureCode.ArabicEgypt, 150, "overview.totalEntries", "إجمالي السجلات"),
                CreateLocalizationSeed(84L, LocalizationCultureCode.ArabicEgypt, 160, "overview.activeEntries", "السجلات الفعالة"),
                CreateLocalizationSeed(85L, LocalizationCultureCode.ArabicEgypt, 170, "overview.submittedEntries", "السجلات المرسلة"),
                CreateLocalizationSeed(86L, LocalizationCultureCode.ArabicEgypt, 180, "overview.currencies", "العملات"),
                CreateLocalizationSeed(87L, LocalizationCultureCode.ArabicEgypt, 190, "overview.uoms", "وحدات القياس"),
                CreateLocalizationSeed(88L, LocalizationCultureCode.ArabicEgypt, 200, "overview.taxCodes", "أكواد الضريبة"),
                CreateLocalizationSeed(89L, LocalizationCultureCode.ArabicEgypt, 210, "overview.warehouses", "المخازن"),
                CreateLocalizationSeed(90L, LocalizationCultureCode.ArabicEgypt, 220, "types.eyebrow", "المجموعات المرجعية"),
                CreateLocalizationSeed(91L, LocalizationCultureCode.ArabicEgypt, 230, "types.title", "عائلات الإعداد التشغيلي"),
                CreateLocalizationSeed(92L, LocalizationCultureCode.ArabicEgypt, 240, "filters.referenceType", "نوع المرجع"),
                CreateLocalizationSeed(93L, LocalizationCultureCode.ArabicEgypt, 250, "filters.activeOnly", "الفعالة فقط"),
                CreateLocalizationSeed(94L, LocalizationCultureCode.ArabicEgypt, 260, "filters.all", "الكل"),
                CreateLocalizationSeed(95L, LocalizationCultureCode.ArabicEgypt, 270, "filters.currency", "عملة"),
                CreateLocalizationSeed(96L, LocalizationCultureCode.ArabicEgypt, 280, "filters.uom", "وحدة قياس"),
                CreateLocalizationSeed(97L, LocalizationCultureCode.ArabicEgypt, 290, "filters.taxCode", "كود ضريبي"),
                CreateLocalizationSeed(98L, LocalizationCultureCode.ArabicEgypt, 300, "filters.warehouse", "مخزن"),
                CreateLocalizationSeed(99L, LocalizationCultureCode.ArabicEgypt, 310, "entry.referenceEntry", "السجل"),
                CreateLocalizationSeed(100L, LocalizationCultureCode.ArabicEgypt, 320, "entry.localized", "الاسم المترجم"),
                CreateLocalizationSeed(101L, LocalizationCultureCode.ArabicEgypt, 330, "entry.attributes", "الخصائص"),
                CreateLocalizationSeed(102L, LocalizationCultureCode.ArabicEgypt, 340, "entry.notSet", "غير محدد"),
                CreateLocalizationSeed(103L, LocalizationCultureCode.ArabicEgypt, 350, "entry.noDescription", "لا يوجد وصف."),
                CreateLocalizationSeed(104L, LocalizationCultureCode.ArabicEgypt, 360, "entry.active", "فعال"),
                CreateLocalizationSeed(105L, LocalizationCultureCode.ArabicEgypt, 370, "form.eyebrow", "إنشاء سجل"),
                CreateLocalizationSeed(106L, LocalizationCultureCode.ArabicEgypt, 380, "form.title", "إنشاء مسودة لسجل محكوم"),
                CreateLocalizationSeed(107L, LocalizationCultureCode.ArabicEgypt, 390, "form.referenceType", "نوع المرجع"),
                CreateLocalizationSeed(108L, LocalizationCultureCode.ArabicEgypt, 400, "form.referenceCode", "كود المرجع"),
                CreateLocalizationSeed(109L, LocalizationCultureCode.ArabicEgypt, 410, "form.referenceName", "اسم المرجع"),
                CreateLocalizationSeed(110L, LocalizationCultureCode.ArabicEgypt, 420, "form.localizedName", "الاسم المترجم"),
                CreateLocalizationSeed(111L, LocalizationCultureCode.ArabicEgypt, 430, "form.effectiveFrom", "ساري من"),
                CreateLocalizationSeed(112L, LocalizationCultureCode.ArabicEgypt, 440, "form.effectiveTo", "ساري إلى"),
                CreateLocalizationSeed(113L, LocalizationCultureCode.ArabicEgypt, 450, "form.description", "الوصف"),
                CreateLocalizationSeed(114L, LocalizationCultureCode.ArabicEgypt, 460, "form.attributesJson", "خصائص JSON"),
                CreateLocalizationSeed(115L, LocalizationCultureCode.ArabicEgypt, 470, "form.submit", "إنشاء مسودة"),
                CreateLocalizationSeed(116L, LocalizationCultureCode.ArabicEgypt, 480, "form.status.ready", "جاهز"),
                CreateLocalizationSeed(117L, LocalizationCultureCode.ArabicEgypt, 490, "form.status.creating", "جار إنشاء المسودة..."),
                CreateLocalizationSeed(118L, LocalizationCultureCode.ArabicEgypt, 500, "form.status.created", "تم إنشاء المسودة"),
                CreateLocalizationSeed(119L, LocalizationCultureCode.ArabicEgypt, 510, "form.status.apiUnavailable", "واجهة البرمجة غير متاحة هنا. التخطيط جاهز للاستضافة الداخلية."),
                CreateLocalizationSeed(120L, LocalizationCultureCode.ArabicEgypt, 520, "form.placeholder.referenceCode", "VAT14"),
                CreateLocalizationSeed(121L, LocalizationCultureCode.ArabicEgypt, 530, "form.placeholder.referenceName", "ضريبة قيمة مضافة 14%"),
                CreateLocalizationSeed(122L, LocalizationCultureCode.ArabicEgypt, 540, "form.placeholder.localizedName", "اسم عربي مترجم"),
                CreateLocalizationSeed(123L, LocalizationCultureCode.ArabicEgypt, 550, "form.placeholder.description", "ملاحظات تشغيلية"),
                CreateLocalizationSeed(124L, LocalizationCultureCode.ArabicEgypt, 560, "form.placeholder.attributesJson", "{\"branchId\":1,\"dispatchEnabled\":true}"),
                CreateLocalizationSeed(125L, LocalizationCultureCode.ArabicEgypt, 570, "queue.eyebrow", "مسار الاعتماد"),
                CreateLocalizationSeed(126L, LocalizationCultureCode.ArabicEgypt, 580, "queue.title", "كيف تبدو الحوكمة عمليا"),
                CreateLocalizationSeed(127L, LocalizationCultureCode.ArabicEgypt, 590, "queue.step1.title", "1. مسودة"),
                CreateLocalizationSeed(128L, LocalizationCultureCode.ArabicEgypt, 600, "queue.step1.body", "يقوم المستخدمون التشغيليون أو الإداريون بإنشاء سجل مرجعي جديد مع خصائص واضحة."),
                CreateLocalizationSeed(129L, LocalizationCultureCode.ArabicEgypt, 610, "queue.step2.title", "2. مرسل"),
                CreateLocalizationSeed(130L, LocalizationCultureCode.ArabicEgypt, 620, "queue.step2.body", "ينتقل السجل إلى قائمة الاعتماد الداخلية تحت رمز الوحدة `MASTER_DATA`."),
                CreateLocalizationSeed(131L, LocalizationCultureCode.ArabicEgypt, 630, "queue.step3.title", "3. معتمد"),
                CreateLocalizationSeed(132L, LocalizationCultureCode.ArabicEgypt, 640, "queue.step3.body", "يراجع المراجع المعنى التجاري وأثر الإعداد دون السماح بالاعتماد الذاتي."),
                CreateLocalizationSeed(133L, LocalizationCultureCode.ArabicEgypt, 650, "queue.step4.title", "4. فعال"),
                CreateLocalizationSeed(134L, LocalizationCultureCode.ArabicEgypt, 660, "queue.step4.body", "يجعل التفعيل السجل التشغيلي جاهزا للاستخدام مع منع التكرار النشط لنفس الكود."),
                CreateLocalizationSeed(135L, LocalizationCultureCode.ArabicEgypt, 670, "culture.english", "English"),
                CreateLocalizationSeed(136L, LocalizationCultureCode.ArabicEgypt, 680, "culture.arabic", "العربية"));
        });
    }

    private static object CreateLocalizationSeed(
        long id,
        string cultureCode,
        int sortOrder,
        string resourceKey,
        string resourceValue)
    {
        var textDirectionCode = string.Equals(cultureCode, LocalizationCultureCode.ArabicEgypt, StringComparison.OrdinalIgnoreCase)
            ? LocalizationDirectionCode.RightToLeft
            : LocalizationDirectionCode.LeftToRight;

        return new
        {
            Id = id,
            ResourceSetCode = LocalizationResourceSetCode.AdminSetupPortal,
            CultureCode = cultureCode,
            ResourceKey = resourceKey,
            ResourceValue = resourceValue,
            TextDirectionCode = textDirectionCode,
            IsActive = true,
            SortOrder = sortOrder
        };
    }

    private static void ConfigureNotifications(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<NotificationTemplate>(builder =>
        {
            builder.ToTable("ntf_template");
            builder.HasKey(template => template.Id);
            builder.Property(template => template.Id).HasColumnName("ntf_template_id");
            builder.Property(template => template.TemplateCode).HasColumnName("template_code").HasMaxLength(60).IsRequired();
            builder.Property(template => template.TemplateName).HasColumnName("template_name").HasMaxLength(200).IsRequired();
            builder.Property(template => template.ChannelCode).HasColumnName("channel_code").HasMaxLength(30).IsRequired();
            builder.Property(template => template.SubjectTemplate).HasColumnName("subject_template_txt").HasMaxLength(500);
            builder.Property(template => template.BodyTemplate).HasColumnName("body_template_txt").IsRequired();
            builder.Property(template => template.StatusId).HasColumnName("status_id");
            builder.Property(template => template.IsActive).HasColumnName("is_active");
            builder.Property(template => template.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(template => template.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(template => template.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(template => template.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(template => template.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(template => template.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(template => template.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(template => template.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(template => template.CreatedByUserId).HasColumnName("created_by");
            builder.Property(template => template.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(template => template.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasData(
                new
                {
                    Id = 1L,
                    TemplateCode = "NTTMP-000001",
                    TemplateName = "Customer Statement Ready",
                    ChannelCode = "EMAIL",
                    SubjectTemplate = "Statement {{statementNumber}} is ready",
                    BodyTemplate = "Dear {{partyName}}, your statement {{statementNumber}} is ready for review.",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seed notification template baseline.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 2L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddMinutes(5),
                    ApprovedByUserId = 4L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddMinutes(6),
                    ActivatedByUserId = 4L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 2L,
                    TemplateCode = "NTTMP-000002",
                    TemplateName = "Financing Request Submitted Portal Confirmation",
                    ChannelCode = "PORTAL",
                    SubjectTemplate = "Financing request {{requestNumber}} submitted",
                    BodyTemplate = "Your financing request {{requestNumber}} for {{productName}} has been submitted and is under CashLine review.",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seed external financing request submission acknowledgment template.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 2L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddMinutes(5),
                    ApprovedByUserId = 4L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddMinutes(6),
                    ActivatedByUserId = 4L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 3L,
                    TemplateCode = "NTTMP-000003",
                    TemplateName = "Financing Request Submitted Officer Alert",
                    ChannelCode = "INBOX",
                    SubjectTemplate = "Financing request {{requestNumber}} awaiting review",
                    BodyTemplate = "Financing request {{requestNumber}} from {{applicantName}} is awaiting Islamic Finance Officer review.",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seed Islamic Finance Officer request-submitted alert template.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 2L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddMinutes(5),
                    ApprovedByUserId = 4L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddMinutes(6),
                    ActivatedByUserId = 4L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 4L,
                    TemplateCode = "NTTMP-000004",
                    TemplateName = "Financing Offer Accepted Portal Confirmation",
                    ChannelCode = "PORTAL",
                    SubjectTemplate = "Offer accepted for {{requestNumber}}",
                    BodyTemplate = "You accepted the financing offer for request {{requestNumber}}. CashLine will continue execution follow-up.",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seed external financing offer acceptance acknowledgment template.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 2L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddMinutes(5),
                    ApprovedByUserId = 4L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddMinutes(6),
                    ActivatedByUserId = 4L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 5L,
                    TemplateCode = "NTTMP-000005",
                    TemplateName = "Financing Offer Accepted Officer Alert",
                    ChannelCode = "INBOX",
                    SubjectTemplate = "Execution follow-up needed for {{requestNumber}}",
                    BodyTemplate = "Request {{requestNumber}} now has an accepted financing offer and is awaiting Islamic Finance Officer follow-up.",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seed Islamic Finance Officer offer-accepted alert template.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 2L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddMinutes(5),
                    ApprovedByUserId = 4L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddMinutes(6),
                    ActivatedByUserId = 4L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 6L,
                    TemplateCode = "NTTMP-000006",
                    TemplateName = "Partner Lender Offer Routing Alert",
                    ChannelCode = "INBOX",
                    SubjectTemplate = "New routed financing request {{requestNumber}}",
                    BodyTemplate = "Financing request {{requestNumber}} for {{productName}} has been routed for partner-lender offer review.",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seed partner-lender routing alert template.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 2L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddMinutes(5),
                    ApprovedByUserId = 4L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddMinutes(6),
                    ActivatedByUserId = 4L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 7L,
                    TemplateCode = "NTTMP-000007",
                    TemplateName = "Partner Lender Routing Officer Alert",
                    ChannelCode = "INBOX",
                    SubjectTemplate = "Partner routing dispatched for {{requestNumber}}",
                    BodyTemplate = "Financing request {{requestNumber}} has been routed to compatible partner lenders and is now in offer collection.",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seed Islamic Finance Officer partner-routing confirmation template.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 2L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddMinutes(5),
                    ApprovedByUserId = 4L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddMinutes(6),
                    ActivatedByUserId = 4L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 8L,
                    TemplateCode = "PARTY_ONBOARDING_CREDENTIAL_EMAIL",
                    TemplateName = "Party Onboarding Credentials Email",
                    ChannelCode = "EMAIL",
                    SubjectTemplate = "Your CashLine access is ready",
                    BodyTemplate = "Dear {{partyName}}, your CashLine access is ready. Username: {{username}} Temporary password: {{temporaryPassword}} Login: {{loginUrl}}",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seed onboarding credential email template.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 2L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddMinutes(5),
                    ApprovedByUserId = 4L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddMinutes(6),
                    ActivatedByUserId = 4L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 9L,
                    TemplateCode = "PARTY_ONBOARDING_CREDENTIAL_SMS",
                    TemplateName = "Party Onboarding Credentials SMS",
                    ChannelCode = "SMS",
                    SubjectTemplate = (string?)null,
                    BodyTemplate = "CashLine access ready. User: {{username}} Temp password: {{temporaryPassword}} Login: {{loginUrl}}",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seed onboarding credential SMS template.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 2L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddMinutes(5),
                    ApprovedByUserId = 4L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddMinutes(6),
                    ActivatedByUserId = 4L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 10L,
                    TemplateCode = "PARTY_ONBOARDING_CREDENTIAL_WHATSAPP",
                    TemplateName = "Party Onboarding Credentials WhatsApp",
                    ChannelCode = "WHATSAPP",
                    SubjectTemplate = (string?)null,
                    BodyTemplate = "CashLine access ready for {{partyName}}. User: {{username}} Temp password: {{temporaryPassword}} Login: {{loginUrl}}",
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seed onboarding credential WhatsApp template.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 2L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddMinutes(5),
                    ApprovedByUserId = 4L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddMinutes(6),
                    ActivatedByUserId = 4L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                });
        });

        modelBuilder.Entity<NotificationQueueItem>(builder =>
        {
            builder.ToTable("ntf_queue");
            builder.HasKey(queueItem => queueItem.Id);
            builder.Property(queueItem => queueItem.Id).HasColumnName("ntf_id");
            builder.Property(queueItem => queueItem.NotificationTemplateId).HasColumnName("ntf_template_id");
            builder.Property(queueItem => queueItem.TemplateCode).HasColumnName("template_code").HasMaxLength(60).IsRequired();
            builder.Property(queueItem => queueItem.ChannelCode).HasColumnName("channel_code").HasMaxLength(30).IsRequired();
            builder.Property(queueItem => queueItem.RecipientReference).HasColumnName("recipient_ref").HasMaxLength(255).IsRequired();
            builder.Property(queueItem => queueItem.ContextCode).HasColumnName("context_code").HasMaxLength(60);
            builder.Property(queueItem => queueItem.RelatedEntityType).HasColumnName("related_entity_type").HasMaxLength(60);
            builder.Property(queueItem => queueItem.RelatedEntityId).HasColumnName("related_entity_id");
            builder.Property(queueItem => queueItem.Subject).HasColumnName("subject_txt").HasMaxLength(255);
            builder.Property(queueItem => queueItem.Body).HasColumnName("body_txt").IsRequired();
            builder.Property(queueItem => queueItem.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(queueItem => queueItem.AttemptNumber).HasColumnName("attempt_no");
            builder.Property(queueItem => queueItem.LastAttemptAtUtc).HasColumnName("last_attempt_at");
            builder.Property(queueItem => queueItem.NextAttemptAtUtc).HasColumnName("next_attempt_at");
            builder.Property(queueItem => queueItem.SentAtUtc).HasColumnName("sent_at");
            builder.Property(queueItem => queueItem.SentByProcess).HasColumnName("sent_by_process").HasMaxLength(60);
            builder.Property(queueItem => queueItem.ErrorText).HasColumnName("error_txt").HasMaxLength(1000);
            builder.Property(queueItem => queueItem.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(queueItem => queueItem.CreatedByUserId).HasColumnName("created_by");
            builder.Property(queueItem => queueItem.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(queueItem => queueItem.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasData(new
            {
                Id = 1L,
                NotificationTemplateId = 1L,
                TemplateCode = "NTTMP-000001",
                ChannelCode = "EMAIL",
                RecipientReference = "finance.checkers@cashline.local",
                ContextCode = "WORKFLOW",
                RelatedEntityType = "PURCHASE_REQUISITION",
                RelatedEntityId = 1L,
                Subject = "Purchase requisition submitted",
                Body = "PR-000001 is awaiting checker review.",
                StatusCode = "PENDING",
                AttemptNumber = 0,
                LastAttemptAtUtc = (DateTime?)null,
                NextAttemptAtUtc = (DateTime?)null,
                SentAtUtc = (DateTime?)null,
                SentByProcess = (string?)null,
                ErrorText = (string?)null,
                CreatedAtUtc = SeedSubmittedAtUtc,
                CreatedByUserId = 1L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });
    }

    private static void ConfigureProcurement(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<PurchaseRequisition>(builder =>
        {
            builder.ToTable("pr_req_hdr");
            builder.HasKey(requisition => requisition.Id);
            builder.Property(requisition => requisition.Id).HasColumnName("pr_req_id");
            builder.Property(requisition => requisition.RequisitionNumber).HasColumnName("req_no").HasMaxLength(60).IsRequired();
            builder.Property(requisition => requisition.BranchId).HasColumnName("branch_id");
            builder.Property(requisition => requisition.RequesterUserId).HasColumnName("requester_id");
            builder.Property(requisition => requisition.RequisitionDate).HasColumnName("req_date");
            builder.Property(requisition => requisition.NeedByDate).HasColumnName("need_by_date");
            builder.Property(requisition => requisition.StatusId).HasColumnName("status_id");
            builder.Property(requisition => requisition.PurposeText).HasColumnName("purpose_txt").HasMaxLength(500);
            builder.Property(requisition => requisition.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10);
            builder.Property(requisition => requisition.EstimatedTotalAmount).HasColumnName("est_total_amt").HasPrecision(18, 2);
            builder.Property(requisition => requisition.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(requisition => requisition.CreatedByUserId).HasColumnName("created_by");
            builder.Property(requisition => requisition.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(requisition => requisition.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(requisition => requisition.Lines)
                .WithOne()
                .HasForeignKey(line => line.PurchaseRequisitionId);

            builder.HasData(new
            {
                Id = 1L,
                RequisitionNumber = "PR-000001",
                BranchId = 1L,
                RequesterUserId = 1L,
                RequisitionDate = new DateOnly(2026, 4, 1),
                NeedByDate = new DateOnly(2026, 4, 7),
                StatusId = WorkflowStatusSeedIds.Submitted,
                PurposeText = "Restock fast-moving warehouse consumables.",
                CurrencyCode = "EGP",
                EstimatedTotalAmount = 2750m,
                CreatedAtUtc = SeedSubmittedAtUtc,
                CreatedByUserId = 1L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<PurchaseRequisitionLine>(builder =>
        {
            builder.ToTable("pr_req_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("pr_req_ln_id");
            builder.Property(line => line.PurchaseRequisitionId).HasColumnName("pr_req_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.RequestedQuantity).HasColumnName("req_qty").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.NeedByDate).HasColumnName("need_by_date");
            builder.Property(line => line.EstimatedUnitPrice).HasColumnName("est_unit_price").HasPrecision(18, 2);
            builder.Property(line => line.StatusId).HasColumnName("status_id");
            builder.Property(line => line.Notes).HasColumnName("notes_txt").HasMaxLength(500);

            builder.HasData(
                new
                {
                    Id = 1L,
                    PurchaseRequisitionId = 1L,
                    LineNumber = 1,
                    ItemId = 1001L,
                    RequestedQuantity = 50m,
                    UnitOfMeasureCode = "EA",
                    NeedByDate = new DateOnly(2026, 4, 7),
                    EstimatedUnitPrice = 25m,
                    StatusId = WorkflowStatusSeedIds.Submitted,
                    Notes = "Primary warehouse replenishment."
                },
                new
                {
                    Id = 2L,
                    PurchaseRequisitionId = 1L,
                    LineNumber = 2,
                    ItemId = 1002L,
                    RequestedQuantity = 30m,
                    UnitOfMeasureCode = "BOX",
                    NeedByDate = new DateOnly(2026, 4, 7),
                    EstimatedUnitPrice = 50m,
                    StatusId = WorkflowStatusSeedIds.Submitted,
                    Notes = "Dispatch packing materials."
                });
        });
    }

    private static void ConfigureSourcing(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<RequestForQuotation>(builder =>
        {
            builder.ToTable("rfq_hdr");
            builder.HasKey(rfq => rfq.Id);
            builder.Property(rfq => rfq.Id).HasColumnName("rfq_id");
            builder.Property(rfq => rfq.RfqNumber).HasColumnName("rfq_no").HasMaxLength(60).IsRequired();
            builder.Property(rfq => rfq.BranchId).HasColumnName("branch_id");
            builder.Property(rfq => rfq.DepartmentId).HasColumnName("dept_id");
            builder.Property(rfq => rfq.PurchaseRequisitionId).HasColumnName("req_id");
            builder.Property(rfq => rfq.RequesterUserId).HasColumnName("requester_user_id");
            builder.Property(rfq => rfq.BuyerUserId).HasColumnName("buyer_user_id");
            builder.Property(rfq => rfq.RfqType).HasColumnName("rfq_type").HasMaxLength(30).IsRequired();
            builder.Property(rfq => rfq.RfqDate).HasColumnName("rfq_date");
            builder.Property(rfq => rfq.ValidUntilDate).HasColumnName("valid_until");
            builder.Property(rfq => rfq.StatusId).HasColumnName("status_id");
            builder.Property(rfq => rfq.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(rfq => rfq.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(rfq => rfq.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(rfq => rfq.CreatedByUserId).HasColumnName("created_by");
            builder.Property(rfq => rfq.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(rfq => rfq.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(rfq => rfq.Lines)
                .WithOne()
                .HasForeignKey(line => line.RequestForQuotationId);

            builder.HasMany(rfq => rfq.Suppliers)
                .WithOne()
                .HasForeignKey(supplier => supplier.RequestForQuotationId);

            builder.HasData(new
            {
                Id = 1L,
                RfqNumber = "RFQ-000001",
                BranchId = 1L,
                DepartmentId = (long?)null,
                PurchaseRequisitionId = 1L,
                RequesterUserId = 1L,
                BuyerUserId = 1L,
                RfqType = "STANDARD",
                RfqDate = new DateOnly(2026, 4, 2),
                ValidUntilDate = new DateOnly(2026, 4, 6),
                StatusId = WorkflowStatusSeedIds.Submitted,
                CurrencyCode = "EGP",
                Notes = "Warehouse consumables competitive sourcing round.",
                CreatedAtUtc = SeedSubmittedAtUtc,
                CreatedByUserId = 1L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<RequestForQuotationLine>(builder =>
        {
            builder.ToTable("rfq_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("rfq_ln_id");
            builder.Property(line => line.RequestForQuotationId).HasColumnName("rfq_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.PurchaseRequisitionLineId).HasColumnName("req_ln_id");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.ItemDescription).HasColumnName("item_desc").HasMaxLength(500);
            builder.Property(line => line.RequestedQuantity).HasColumnName("qty_req").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.NeedByDate).HasColumnName("need_by_date");
            builder.Property(line => line.TaxCode).HasColumnName("tax_code").HasMaxLength(30);
            builder.Property(line => line.TargetUnitPrice).HasColumnName("target_unit_price").HasPrecision(18, 2);
            builder.Property(line => line.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.HasData(
                new
                {
                    Id = 1L,
                    RequestForQuotationId = 1L,
                    LineNumber = 1,
                    PurchaseRequisitionLineId = 1L,
                    ItemId = 1001L,
                    ItemDescription = "Warehouse consumable item 1001",
                    RequestedQuantity = 50m,
                    UnitOfMeasureCode = "EA",
                    NeedByDate = new DateOnly(2026, 4, 7),
                    TaxCode = "VAT14",
                    TargetUnitPrice = 25m,
                    Notes = "Urgent replenishment"
                },
                new
                {
                    Id = 2L,
                    RequestForQuotationId = 1L,
                    LineNumber = 2,
                    PurchaseRequisitionLineId = 2L,
                    ItemId = 1002L,
                    ItemDescription = "Dispatch packing material 1002",
                    RequestedQuantity = 30m,
                    UnitOfMeasureCode = "BOX",
                    NeedByDate = new DateOnly(2026, 4, 7),
                    TaxCode = "VAT14",
                    TargetUnitPrice = 50m,
                    Notes = "Secondary warehouse demand"
                });
        });

        modelBuilder.Entity<RequestForQuotationSupplier>(builder =>
        {
            builder.ToTable("rfq_supplier");
            builder.HasKey(supplier => supplier.Id);
            builder.Property(supplier => supplier.Id).HasColumnName("rfq_supplier_id");
            builder.Property(supplier => supplier.RequestForQuotationId).HasColumnName("rfq_id");
            builder.Property(supplier => supplier.SupplierId).HasColumnName("supplier_id");
            builder.Property(supplier => supplier.InviteStatus).HasColumnName("invite_status").HasMaxLength(30).IsRequired();
            builder.Property(supplier => supplier.InvitedAtUtc).HasColumnName("invited_at");
            builder.Property(supplier => supplier.RespondedAtUtc).HasColumnName("responded_at");
            builder.Property(supplier => supplier.DeclineReason).HasColumnName("decline_reason").HasMaxLength(500);

            builder.HasData(new
            {
                Id = 1L,
                RequestForQuotationId = 1L,
                SupplierId = 1L,
                InviteStatus = "INVITED",
                InvitedAtUtc = SeedSubmittedAtUtc,
                RespondedAtUtc = (DateTime?)null,
                DeclineReason = (string?)null
            });
        });

        modelBuilder.Entity<SupplierQuotation>(builder =>
        {
            builder.ToTable("qtn_hdr");
            builder.HasKey(quotation => quotation.Id);
            builder.Property(quotation => quotation.Id).HasColumnName("qtn_id");
            builder.Property(quotation => quotation.QuotationNumber).HasColumnName("qtn_no").HasMaxLength(60).IsRequired();
            builder.Property(quotation => quotation.RequestForQuotationId).HasColumnName("rfq_id");
            builder.Property(quotation => quotation.SupplierId).HasColumnName("supplier_id");
            builder.Property(quotation => quotation.QuoteDate).HasColumnName("quote_date");
            builder.Property(quotation => quotation.ValidUntilDate).HasColumnName("valid_until");
            builder.Property(quotation => quotation.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(quotation => quotation.FxRate).HasColumnName("fx_rate").HasPrecision(18, 6);
            builder.Property(quotation => quotation.StatusId).HasColumnName("status_id");
            builder.Property(quotation => quotation.SubtotalAmount).HasColumnName("subtotal_amt").HasPrecision(18, 2);
            builder.Property(quotation => quotation.DiscountAmount).HasColumnName("discount_amt").HasPrecision(18, 2);
            builder.Property(quotation => quotation.TaxAmount).HasColumnName("tax_amt").HasPrecision(18, 2);
            builder.Property(quotation => quotation.TotalAmount).HasColumnName("total_amt").HasPrecision(18, 2);
            builder.Property(quotation => quotation.IsSelected).HasColumnName("is_selected");
            builder.Property(quotation => quotation.SelectedAtUtc).HasColumnName("selected_at");
            builder.Property(quotation => quotation.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(quotation => quotation.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(quotation => quotation.CreatedByUserId).HasColumnName("created_by");
            builder.Property(quotation => quotation.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(quotation => quotation.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(quotation => quotation.Lines)
                .WithOne()
                .HasForeignKey(line => line.SupplierQuotationId);

            builder.HasData(new
            {
                Id = 1L,
                QuotationNumber = "QTN-000001",
                RequestForQuotationId = 1L,
                SupplierId = 1L,
                QuoteDate = new DateOnly(2026, 4, 3),
                ValidUntilDate = new DateOnly(2026, 4, 10),
                CurrencyCode = "EGP",
                FxRate = (decimal?)null,
                StatusId = WorkflowStatusSeedIds.Submitted,
                SubtotalAmount = 2625m,
                DiscountAmount = 125m,
                TaxAmount = 367.5m,
                TotalAmount = 2992.5m,
                IsSelected = false,
                SelectedAtUtc = (DateTime?)null,
                Notes = "Initial supplier quotation",
                CreatedAtUtc = SeedSubmittedAtUtc,
                CreatedByUserId = 1L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<SupplierQuotationLine>(builder =>
        {
            builder.ToTable("qtn_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("qtn_ln_id");
            builder.Property(line => line.SupplierQuotationId).HasColumnName("qtn_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.RequestForQuotationLineId).HasColumnName("rfq_ln_id");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.QuotedQuantity).HasColumnName("qty_quote").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.UnitPrice).HasColumnName("unit_price").HasPrecision(18, 2);
            builder.Property(line => line.DiscountPercent).HasColumnName("discount_pct").HasPrecision(9, 4);
            builder.Property(line => line.DiscountAmount).HasColumnName("discount_amt").HasPrecision(18, 2);
            builder.Property(line => line.TaxCode).HasColumnName("tax_code").HasMaxLength(30);
            builder.Property(line => line.LineNetAmount).HasColumnName("line_net_amt").HasPrecision(18, 2);
            builder.Property(line => line.LineTaxAmount).HasColumnName("line_tax_amt").HasPrecision(18, 2);
            builder.Property(line => line.LineTotalAmount).HasColumnName("line_total_amt").HasPrecision(18, 2);
            builder.Property(line => line.LeadTimeDays).HasColumnName("lead_time_days");

            builder.HasData(
                new
                {
                    Id = 1L,
                    SupplierQuotationId = 1L,
                    LineNumber = 1,
                    RequestForQuotationLineId = 1L,
                    ItemId = 1001L,
                    QuotedQuantity = 50m,
                    UnitOfMeasureCode = "EA",
                    UnitPrice = 24m,
                    DiscountPercent = 0m,
                    DiscountAmount = 0m,
                    TaxCode = "VAT14",
                    LineNetAmount = 1200m,
                    LineTaxAmount = 168m,
                    LineTotalAmount = 1368m,
                    LeadTimeDays = 2
                },
                new
                {
                    Id = 2L,
                    SupplierQuotationId = 1L,
                    LineNumber = 2,
                    RequestForQuotationLineId = 2L,
                    ItemId = 1002L,
                    QuotedQuantity = 30m,
                    UnitOfMeasureCode = "BOX",
                    UnitPrice = 50m,
                    DiscountPercent = 0m,
                    DiscountAmount = 75m,
                    TaxCode = "VAT14",
                    LineNetAmount = 1425m,
                    LineTaxAmount = 199.5m,
                    LineTotalAmount = 1624.5m,
                    LeadTimeDays = 3
                });
        });
    }

    private static void ConfigureCommercialDecision(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<RfqEvaluation>(builder =>
        {
            builder.ToTable("rfq_eval_hdr");
            builder.HasKey(evaluation => evaluation.Id);
            builder.Property(evaluation => evaluation.Id).HasColumnName("rfq_eval_id");
            builder.Property(evaluation => evaluation.RequestForQuotationId).HasColumnName("rfq_id");
            builder.Property(evaluation => evaluation.EvaluationNumber).HasColumnName("eval_no").HasMaxLength(60).IsRequired();
            builder.Property(evaluation => evaluation.EvaluationDate).HasColumnName("eval_date");
            builder.Property(evaluation => evaluation.StatusId).HasColumnName("status_id");
            builder.Property(evaluation => evaluation.RecommendedSupplierId).HasColumnName("recommended_supplier_id");
            builder.Property(evaluation => evaluation.ApprovedQuotationId).HasColumnName("approved_qtn_id");
            builder.Property(evaluation => evaluation.Notes).HasColumnName("notes_txt").HasMaxLength(1500);
            builder.Property(evaluation => evaluation.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(evaluation => evaluation.CreatedByUserId).HasColumnName("created_by");
            builder.Property(evaluation => evaluation.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(evaluation => evaluation.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(evaluation => evaluation.Lines)
                .WithOne()
                .HasForeignKey(line => line.RfqEvaluationId);

            builder.HasData(new
            {
                Id = 1L,
                RequestForQuotationId = 1L,
                EvaluationNumber = "EVAL-000001",
                EvaluationDate = new DateOnly(2026, 4, 4),
                StatusId = WorkflowStatusSeedIds.Approved,
                RecommendedSupplierId = 1L,
                ApprovedQuotationId = 1L,
                Notes = "Supplier ranked first on price and delivery.",
                CreatedAtUtc = SeedSubmittedAtUtc,
                CreatedByUserId = 2L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<RfqEvaluationLine>(builder =>
        {
            builder.ToTable("rfq_eval_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("rfq_eval_ln_id");
            builder.Property(line => line.RfqEvaluationId).HasColumnName("rfq_eval_id");
            builder.Property(line => line.QuotationId).HasColumnName("qtn_id");
            builder.Property(line => line.SupplierId).HasColumnName("supplier_id");
            builder.Property(line => line.PriceScore).HasColumnName("price_score").HasPrecision(9, 4);
            builder.Property(line => line.CommercialScore).HasColumnName("commercial_score").HasPrecision(9, 4);
            builder.Property(line => line.DeliveryScore).HasColumnName("delivery_score").HasPrecision(9, 4);
            builder.Property(line => line.QualityScore).HasColumnName("quality_score").HasPrecision(9, 4);
            builder.Property(line => line.TotalScore).HasColumnName("total_score").HasPrecision(9, 4);
            builder.Property(line => line.RankNumber).HasColumnName("rank_no");
            builder.Property(line => line.IsRecommended).HasColumnName("is_recommended");
            builder.Property(line => line.Notes).HasColumnName("notes_txt").HasMaxLength(1000);

            builder.HasData(new
            {
                Id = 1L,
                RfqEvaluationId = 1L,
                QuotationId = 1L,
                SupplierId = 1L,
                PriceScore = 40m,
                CommercialScore = 20m,
                DeliveryScore = 20m,
                QualityScore = 15m,
                TotalScore = 95m,
                RankNumber = 1,
                IsRecommended = true,
                Notes = "Best overall fit"
            });
        });

        modelBuilder.Entity<PurchaseOrder>(builder =>
        {
            builder.ToTable("po_hdr");
            builder.HasKey(purchaseOrder => purchaseOrder.Id);
            builder.Property(purchaseOrder => purchaseOrder.Id).HasColumnName("po_id");
            builder.Property(purchaseOrder => purchaseOrder.PurchaseOrderNumber).HasColumnName("po_no").HasMaxLength(60).IsRequired();
            builder.Property(purchaseOrder => purchaseOrder.BranchId).HasColumnName("branch_id");
            builder.Property(purchaseOrder => purchaseOrder.SupplierId).HasColumnName("supplier_id");
            builder.Property(purchaseOrder => purchaseOrder.PurchaseRequisitionId).HasColumnName("pr_req_id");
            builder.Property(purchaseOrder => purchaseOrder.PurchaseOrderDate).HasColumnName("po_date");
            builder.Property(purchaseOrder => purchaseOrder.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(purchaseOrder => purchaseOrder.ExchangeRate).HasColumnName("exchange_rate").HasPrecision(18, 6);
            builder.Property(purchaseOrder => purchaseOrder.StatusId).HasColumnName("status_id");
            builder.Property(purchaseOrder => purchaseOrder.SubtotalAmount).HasColumnName("subtotal_amt").HasPrecision(18, 2);
            builder.Property(purchaseOrder => purchaseOrder.TaxAmount).HasColumnName("tax_amt").HasPrecision(18, 2);
            builder.Property(purchaseOrder => purchaseOrder.TotalAmount).HasColumnName("total_amt").HasPrecision(18, 2);
            builder.Property(purchaseOrder => purchaseOrder.SupplierAcknowledgmentStatusCode).HasColumnName("sup_ack_status_code").HasMaxLength(30);
            builder.Property(purchaseOrder => purchaseOrder.SupplierAcknowledgedAtUtc).HasColumnName("sup_ack_at");
            builder.Property(purchaseOrder => purchaseOrder.SupplierAcknowledgedByUserId).HasColumnName("sup_ack_by");
            builder.Property(purchaseOrder => purchaseOrder.SupplierAcknowledgmentNotes).HasColumnName("sup_ack_notes").HasMaxLength(400);
            builder.Property(purchaseOrder => purchaseOrder.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(purchaseOrder => purchaseOrder.CreatedByUserId).HasColumnName("created_by");
            builder.Property(purchaseOrder => purchaseOrder.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(purchaseOrder => purchaseOrder.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(purchaseOrder => purchaseOrder.Lines)
                .WithOne()
                .HasForeignKey(line => line.PurchaseOrderId);

            builder.HasData(new
            {
                Id = 1L,
                PurchaseOrderNumber = "PO-000001",
                BranchId = 1L,
                SupplierId = 1L,
                PurchaseRequisitionId = 1L,
                PurchaseOrderDate = new DateOnly(2026, 4, 4),
                CurrencyCode = "EGP",
                ExchangeRate = 1m,
                StatusId = WorkflowStatusSeedIds.Approved,
                SubtotalAmount = 2625m,
                TaxAmount = 367.5m,
                TotalAmount = 2992.5m,
                CreatedAtUtc = SeedSubmittedAtUtc,
                CreatedByUserId = 2L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<PurchaseOrderLine>(builder =>
        {
            builder.ToTable("po_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("po_ln_id");
            builder.Property(line => line.PurchaseOrderId).HasColumnName("po_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.WarehouseId).HasColumnName("wh_id");
            builder.Property(line => line.OrderedQuantity).HasColumnName("qty_ordered").HasPrecision(18, 4);
            builder.Property(line => line.ReceivedQuantity).HasColumnName("qty_received").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.UnitPrice).HasColumnName("unit_price").HasPrecision(18, 2);
            builder.Property(line => line.TaxCode).HasColumnName("tax_code").HasMaxLength(30);
            builder.Property(line => line.LineNetAmount).HasColumnName("line_net_amt").HasPrecision(18, 2);
            builder.Property(line => line.LineTaxAmount).HasColumnName("line_tax_amt").HasPrecision(18, 2);
            builder.Property(line => line.LineTotalAmount).HasColumnName("line_total_amt").HasPrecision(18, 2);

            builder.HasData(
                new
                {
                    Id = 1L,
                    PurchaseOrderId = 1L,
                    LineNumber = 1,
                    ItemId = 1001L,
                    WarehouseId = 1L,
                    OrderedQuantity = 50m,
                    ReceivedQuantity = 50m,
                    UnitOfMeasureCode = "EA",
                    UnitPrice = 24m,
                    TaxCode = "VAT14",
                    LineNetAmount = 1200m,
                    LineTaxAmount = 168m,
                    LineTotalAmount = 1368m
                },
                new
                {
                    Id = 2L,
                    PurchaseOrderId = 1L,
                    LineNumber = 2,
                    ItemId = 1002L,
                    WarehouseId = 1L,
                    OrderedQuantity = 30m,
                    ReceivedQuantity = 30m,
                    UnitOfMeasureCode = "BOX",
                    UnitPrice = 50m,
                    TaxCode = "VAT14",
                    LineNetAmount = 1425m,
                    LineTaxAmount = 199.5m,
                    LineTotalAmount = 1624.5m
                });
        });
    }

    private static void ConfigureReceivingAndPayables(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<GoodsReceipt>(builder =>
        {
            builder.ToTable("grn_hdr");
            builder.HasKey(goodsReceipt => goodsReceipt.Id);
            builder.Property(goodsReceipt => goodsReceipt.Id).HasColumnName("grn_id");
            builder.Property(goodsReceipt => goodsReceipt.GoodsReceiptNumber).HasColumnName("grn_no").HasMaxLength(60).IsRequired();
            builder.Property(goodsReceipt => goodsReceipt.BranchId).HasColumnName("branch_id");
            builder.Property(goodsReceipt => goodsReceipt.PurchaseOrderId).HasColumnName("po_id");
            builder.Property(goodsReceipt => goodsReceipt.SupplierId).HasColumnName("supplier_id");
            builder.Property(goodsReceipt => goodsReceipt.ReceivedAtUtc).HasColumnName("received_at");
            builder.Property(goodsReceipt => goodsReceipt.ReceivedByUserId).HasColumnName("received_by");
            builder.Property(goodsReceipt => goodsReceipt.StatusId).HasColumnName("status_id");
            builder.Property(goodsReceipt => goodsReceipt.InspectionStatus).HasColumnName("inspection_status").HasMaxLength(30).IsRequired();
            builder.Property(goodsReceipt => goodsReceipt.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(goodsReceipt => goodsReceipt.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(goodsReceipt => goodsReceipt.UpdatedAtUtc);
            builder.Ignore(goodsReceipt => goodsReceipt.UpdatedByUserId);

            builder.HasMany(goodsReceipt => goodsReceipt.Lines)
                .WithOne()
                .HasForeignKey(line => line.GoodsReceiptId);

            builder.HasData(new
            {
                Id = 1L,
                GoodsReceiptNumber = "GRN-000001",
                BranchId = 1L,
                PurchaseOrderId = 1L,
                SupplierId = 1L,
                ReceivedAtUtc = SeedSubmittedAtUtc.AddDays(1),
                ReceivedByUserId = 1L,
                StatusId = WorkflowStatusSeedIds.Posted,
                InspectionStatus = "RECEIVED",
                CreatedAtUtc = SeedSubmittedAtUtc.AddDays(1),
                CreatedByUserId = 1L
            });
        });

        modelBuilder.Entity<GoodsReceiptLine>(builder =>
        {
            builder.ToTable("grn_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("grn_ln_id");
            builder.Property(line => line.GoodsReceiptId).HasColumnName("grn_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.PurchaseOrderLineId).HasColumnName("po_ln_id");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.WarehouseId).HasColumnName("wh_id");
            builder.Property(line => line.WarehouseLocationId).HasColumnName("wh_loc_id");
            builder.Property(line => line.QuantityReceived).HasColumnName("qty_received").HasPrecision(18, 4);
            builder.Property(line => line.QuantityAccepted).HasColumnName("qty_accepted").HasPrecision(18, 4);
            builder.Property(line => line.QuantityRejected).HasColumnName("qty_rejected").HasPrecision(18, 4);
            builder.Property(line => line.BatchNumber).HasColumnName("batch_no").HasMaxLength(60);
            builder.Property(line => line.SerialNumber).HasColumnName("serial_no").HasMaxLength(100);

            builder.HasData(
                new
                {
                    Id = 1L,
                    GoodsReceiptId = 1L,
                    LineNumber = 1,
                    PurchaseOrderLineId = 1L,
                    ItemId = 1001L,
                    WarehouseId = 1L,
                    WarehouseLocationId = (long?)null,
                    QuantityReceived = 50m,
                    QuantityAccepted = 50m,
                    QuantityRejected = 0m,
                    BatchNumber = "BATCH-1001-A",
                    SerialNumber = (string?)null
                },
                new
                {
                    Id = 2L,
                    GoodsReceiptId = 1L,
                    LineNumber = 2,
                    PurchaseOrderLineId = 2L,
                    ItemId = 1002L,
                    WarehouseId = 1L,
                    WarehouseLocationId = (long?)null,
                    QuantityReceived = 30m,
                    QuantityAccepted = 30m,
                    QuantityRejected = 0m,
                    BatchNumber = "BATCH-1002-A",
                    SerialNumber = (string?)null
                });
        });

        modelBuilder.Entity<PurchaseReturn>(builder =>
        {
            builder.ToTable("po_rtn_hdr");
            builder.HasKey(purchaseReturn => purchaseReturn.Id);
            builder.Property(purchaseReturn => purchaseReturn.Id).HasColumnName("po_rtn_id");
            builder.Property(purchaseReturn => purchaseReturn.PurchaseReturnNumber).HasColumnName("po_rtn_no").HasMaxLength(60).IsRequired();
            builder.Property(purchaseReturn => purchaseReturn.BranchId).HasColumnName("branch_id");
            builder.Property(purchaseReturn => purchaseReturn.SupplierId).HasColumnName("supplier_id");
            builder.Property(purchaseReturn => purchaseReturn.PurchaseOrderId).HasColumnName("po_id");
            builder.Property(purchaseReturn => purchaseReturn.GoodsReceiptId).HasColumnName("grn_id");
            builder.Property(purchaseReturn => purchaseReturn.ReturnDate).HasColumnName("return_date");
            builder.Property(purchaseReturn => purchaseReturn.ReturnWarehouseId).HasColumnName("return_wh_id");
            builder.Property(purchaseReturn => purchaseReturn.ReasonCode).HasColumnName("reason_code").HasMaxLength(60).IsRequired();
            builder.Property(purchaseReturn => purchaseReturn.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(purchaseReturn => purchaseReturn.StatusId).HasColumnName("status_id");
            builder.Property(purchaseReturn => purchaseReturn.TotalReturnedQuantity).HasColumnName("total_return_qty").HasPrecision(18, 4);
            builder.Property(purchaseReturn => purchaseReturn.DebitNoteBillId).HasColumnName("debit_note_ap_bill_id");
            builder.Property(purchaseReturn => purchaseReturn.DebitNoteIssuedAtUtc).HasColumnName("debit_note_issued_at");
            builder.Property(purchaseReturn => purchaseReturn.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(purchaseReturn => purchaseReturn.CreatedByUserId).HasColumnName("created_by");
            builder.Property(purchaseReturn => purchaseReturn.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(purchaseReturn => purchaseReturn.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(purchaseReturn => purchaseReturn.Lines)
                .WithOne()
                .HasForeignKey(line => line.PurchaseReturnId);
        });

        modelBuilder.Entity<PurchaseReturnLine>(builder =>
        {
            builder.ToTable("po_rtn_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("po_rtn_ln_id");
            builder.Property(line => line.PurchaseReturnId).HasColumnName("po_rtn_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.GoodsReceiptLineId).HasColumnName("grn_ln_id");
            builder.Property(line => line.PurchaseOrderLineId).HasColumnName("po_ln_id");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.QuantityReturned).HasColumnName("qty_returned").HasPrecision(18, 4);
            builder.Property(line => line.WarehouseLocationId).HasColumnName("wh_loc_id");
            builder.Property(line => line.BatchNumber).HasColumnName("batch_no").HasMaxLength(80);
            builder.Property(line => line.SerialNumber).HasColumnName("serial_no").HasMaxLength(120);
            builder.Property(line => line.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
        });

        modelBuilder.Entity<AccountsPayableBill>(builder =>
        {
            builder.ToTable("ap_bill_hdr");
            builder.HasKey(bill => bill.Id);
            builder.Property(bill => bill.Id).HasColumnName("ap_bill_id");
            builder.Property(bill => bill.BillNumber).HasColumnName("bill_no").HasMaxLength(60).IsRequired();
            builder.Property(bill => bill.SupplierId).HasColumnName("supplier_id");
            builder.Property(bill => bill.PurchaseOrderId).HasColumnName("po_id");
            builder.Property(bill => bill.GoodsReceiptId).HasColumnName("grn_id");
            builder.Property(bill => bill.PurchaseReturnId).HasColumnName("po_rtn_id");
            builder.Property(bill => bill.BillType).HasColumnName("bill_type").HasMaxLength(30).IsRequired();
            builder.Property(bill => bill.BillDate).HasColumnName("bill_date");
            builder.Property(bill => bill.DueDate).HasColumnName("due_date");
            builder.Property(bill => bill.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(bill => bill.StatusId).HasColumnName("status_id");
            builder.Property(bill => bill.ThreeWayMatchStatus).HasColumnName("match_status").HasMaxLength(30).IsRequired();
            builder.Property(bill => bill.MatchVarianceAmount).HasColumnName("match_variance_amt").HasPrecision(18, 2);
            builder.Property(bill => bill.MatchNotes).HasColumnName("match_notes_txt").HasMaxLength(1000);
            builder.Property(bill => bill.DisputeStatusCode).HasColumnName("dispute_status_code").HasMaxLength(30).IsRequired();
            builder.Property(bill => bill.DisputeReasonCode).HasColumnName("dispute_reason_code").HasMaxLength(60);
            builder.Property(bill => bill.DisputeNotes).HasColumnName("dispute_notes_txt").HasMaxLength(1000);
            builder.Property(bill => bill.HeldAtUtc).HasColumnName("held_at");
            builder.Property(bill => bill.HeldByUserId).HasColumnName("held_by");
            builder.Property(bill => bill.ResolvedAtUtc).HasColumnName("resolved_at");
            builder.Property(bill => bill.ResolvedByUserId).HasColumnName("resolved_by");
            builder.Property(bill => bill.ResolutionDecisionCode).HasColumnName("resolution_decision_code").HasMaxLength(30);
            builder.Property(bill => bill.ResolutionNotes).HasColumnName("resolution_notes_txt").HasMaxLength(1000);
            builder.Property(bill => bill.MatchedAtUtc).HasColumnName("matched_at");
            builder.Property(bill => bill.MatchedByUserId).HasColumnName("matched_by");
            builder.Property(bill => bill.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(bill => bill.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(bill => bill.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(bill => bill.PostedByUserId).HasColumnName("posted_by");
            builder.Property(bill => bill.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(bill => bill.SubtotalAmount).HasColumnName("subtotal_amt").HasPrecision(18, 2);
            builder.Property(bill => bill.TaxAmount).HasColumnName("tax_amt").HasPrecision(18, 2);
            builder.Property(bill => bill.TotalAmount).HasColumnName("total_amt").HasPrecision(18, 2);
            builder.Property(bill => bill.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(bill => bill.CreatedByUserId).HasColumnName("created_by");
            builder.Property(bill => bill.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(bill => bill.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(bill => bill.Lines)
                .WithOne()
                .HasForeignKey(line => line.AccountsPayableBillId);

            builder.HasData(new
            {
                Id = 1L,
                BillNumber = "BILL-000001",
                SupplierId = 1L,
                PurchaseOrderId = 1L,
                GoodsReceiptId = 1L,
                PurchaseReturnId = (long?)null,
                BillType = "INVOICE",
                BillDate = new DateOnly(2026, 4, 5),
                DueDate = new DateOnly(2026, 4, 20),
                CurrencyCode = "EGP",
                StatusId = WorkflowStatusSeedIds.Posted,
                ThreeWayMatchStatus = "MATCHED",
                DisputeStatusCode = "CLEAR",
                DisputeReasonCode = (string?)null,
                DisputeNotes = (string?)null,
                HeldAtUtc = (DateTime?)null,
                HeldByUserId = (long?)null,
                ResolvedAtUtc = (DateTime?)null,
                ResolvedByUserId = (long?)null,
                ResolutionDecisionCode = (string?)null,
                ResolutionNotes = (string?)null,
                MatchVarianceAmount = 0m,
                MatchNotes = "Three-way match cleared with no variances.",
                MatchedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                MatchedByUserId = 4L,
                ApprovedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                ApprovedByUserId = 4L,
                PostedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                PostedByUserId = 4L,
                GeneralLedgerBatchId = 1L,
                SubtotalAmount = 2625m,
                TaxAmount = 367.5m,
                TotalAmount = 2992.5m,
                CreatedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                CreatedByUserId = 2L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<AccountsPayableBillLine>(builder =>
        {
            builder.ToTable("ap_bill_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("ap_bill_ln_id");
            builder.Property(line => line.AccountsPayableBillId).HasColumnName("ap_bill_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.PurchaseOrderLineId).HasColumnName("po_ln_id");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.QuantityBilled).HasColumnName("qty_billed").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20);
            builder.Property(line => line.UnitPrice).HasColumnName("unit_price").HasPrecision(18, 2);
            builder.Property(line => line.TaxCode).HasColumnName("tax_code").HasMaxLength(30);
            builder.Property(line => line.LineNetAmount).HasColumnName("line_net_amt").HasPrecision(18, 2);
            builder.Property(line => line.LineTaxAmount).HasColumnName("line_tax_amt").HasPrecision(18, 2);
            builder.Property(line => line.LineTotalAmount).HasColumnName("line_total_amt").HasPrecision(18, 2);

            builder.HasData(
                new
                {
                    Id = 1L,
                    AccountsPayableBillId = 1L,
                    LineNumber = 1,
                    PurchaseOrderLineId = 1L,
                    ItemId = 1001L,
                    QuantityBilled = 50m,
                    UnitOfMeasureCode = "EA",
                    UnitPrice = 24m,
                    TaxCode = "VAT14",
                    LineNetAmount = 1200m,
                    LineTaxAmount = 168m,
                    LineTotalAmount = 1368m
                },
                new
                {
                    Id = 2L,
                    AccountsPayableBillId = 1L,
                    LineNumber = 2,
                    PurchaseOrderLineId = 2L,
                    ItemId = 1002L,
                    QuantityBilled = 30m,
                    UnitOfMeasureCode = "BOX",
                    UnitPrice = 47.5m,
                    TaxCode = "VAT14",
                    LineNetAmount = 1425m,
                    LineTaxAmount = 199.5m,
                    LineTotalAmount = 1624.5m
                });
        });
    }

    private static void ConfigureSalesAndDispatch(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<SalesOrder>(builder =>
        {
            builder.ToTable("so_hdr");
            builder.HasKey(order => order.Id);
            builder.Property(order => order.Id).HasColumnName("so_id");
            builder.Property(order => order.SalesOrderNumber).HasColumnName("so_no").HasMaxLength(60).IsRequired();
            builder.Property(order => order.BranchId).HasColumnName("branch_id");
            builder.Property(order => order.CustomerId).HasColumnName("customer_id");
            builder.Property(order => order.OrderDate).HasColumnName("order_date");
            builder.Property(order => order.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(order => order.ExchangeRate).HasColumnName("exchange_rate").HasPrecision(18, 6);
            builder.Property(order => order.StatusId).HasColumnName("status_id");
            builder.Property(order => order.CreditStatusCode).HasColumnName("credit_status_code").HasMaxLength(30).IsRequired();
            builder.Property(order => order.CreditHoldReason).HasColumnName("credit_hold_reason").HasMaxLength(500);
            builder.Property(order => order.CreditLimitAmountAtCheck).HasColumnName("credit_limit_at_check").HasPrecision(18, 2);
            builder.Property(order => order.CreditExposureAmountAtCheck).HasColumnName("credit_exposure_at_check").HasPrecision(18, 2);
            builder.Property(order => order.OverdueInvoiceCountAtCheck).HasColumnName("overdue_invoice_count");
            builder.Property(order => order.CreditCheckedAtUtc).HasColumnName("credit_checked_at");
            builder.Property(order => order.CreditReleaseDecisionCode).HasColumnName("credit_release_decision_code").HasMaxLength(30);
            builder.Property(order => order.CreditReleaseNotes).HasColumnName("credit_release_notes").HasMaxLength(1000);
            builder.Property(order => order.CreditReleasedAtUtc).HasColumnName("credit_released_at");
            builder.Property(order => order.CreditReleasedByUserId).HasColumnName("credit_released_by");
            builder.Property(order => order.SubtotalAmount).HasColumnName("subtotal_amt").HasPrecision(18, 2);
            builder.Property(order => order.TaxAmount).HasColumnName("tax_amt").HasPrecision(18, 2);
            builder.Property(order => order.TotalAmount).HasColumnName("total_amt").HasPrecision(18, 2);
            builder.Property(order => order.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(order => order.CreatedByUserId).HasColumnName("created_by");
            builder.Property(order => order.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(order => order.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(order => order.Lines)
                .WithOne()
                .HasForeignKey(line => line.SalesOrderId);

            builder.HasData(new
            {
                Id = 1L,
                SalesOrderNumber = "SO-000001",
                BranchId = 1L,
                CustomerId = 2L,
                OrderDate = new DateOnly(2026, 4, 5),
                CurrencyCode = "EGP",
                ExchangeRate = 1m,
                StatusId = WorkflowStatusSeedIds.Approved,
                CreditStatusCode = "CLEAR",
                CreditHoldReason = (string?)null,
                CreditLimitAmountAtCheck = 5000m,
                CreditExposureAmountAtCheck = 3477m,
                OverdueInvoiceCountAtCheck = 0,
                CreditCheckedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                CreditReleaseDecisionCode = (string?)null,
                CreditReleaseNotes = (string?)null,
                CreditReleasedAtUtc = (DateTime?)null,
                CreditReleasedByUserId = (long?)null,
                SubtotalAmount = 3050m,
                TaxAmount = 427m,
                TotalAmount = 3477m,
                CreatedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                CreatedByUserId = 2L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<SalesOrderLine>(builder =>
        {
            builder.ToTable("so_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("so_ln_id");
            builder.Property(line => line.SalesOrderId).HasColumnName("so_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.WarehouseId).HasColumnName("wh_id");
            builder.Property(line => line.OrderedQuantity).HasColumnName("qty_ordered").HasPrecision(18, 4);
            builder.Property(line => line.AllocatedQuantity).HasColumnName("qty_allocated").HasPrecision(18, 4);
            builder.Property(line => line.DeliveredQuantity).HasColumnName("qty_delivered").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.UnitPrice).HasColumnName("unit_price").HasPrecision(18, 2);
            builder.Property(line => line.BaseUnitPrice).HasColumnName("base_unit_price").HasPrecision(18, 2);
            builder.Property(line => line.PricingRuleId).HasColumnName("price_rule_id");
            builder.Property(line => line.PricingRuleCode).HasColumnName("price_rule_code").HasMaxLength(60);
            builder.Property(line => line.PricingSourceCode).HasColumnName("pricing_source_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.DiscountAmount).HasColumnName("discount_amt").HasPrecision(18, 2);
            builder.Property(line => line.DiscountPercent).HasColumnName("discount_pct").HasPrecision(9, 4);
            builder.Property(line => line.DiscountOverrideId).HasColumnName("discount_override_id");
            builder.Property(line => line.DiscountSourceCode).HasColumnName("discount_source_code").HasMaxLength(30).IsRequired();
            builder.Property(line => line.TaxCode).HasColumnName("tax_code").HasMaxLength(30);
            builder.Property(line => line.LineNetAmount).HasColumnName("line_net_amt").HasPrecision(18, 2);
            builder.Property(line => line.LineTaxAmount).HasColumnName("line_tax_amt").HasPrecision(18, 2);
            builder.Property(line => line.LineTotalAmount).HasColumnName("line_total_amt").HasPrecision(18, 2);

            builder.HasData(
                new
                {
                    Id = 1L,
                    SalesOrderId = 1L,
                    LineNumber = 1,
                    ItemId = 1001L,
                    WarehouseId = 1L,
                    OrderedQuantity = 25m,
                    AllocatedQuantity = 0m,
                    DeliveredQuantity = 0m,
                    UnitOfMeasureCode = "EA",
                    UnitPrice = 32m,
                    BaseUnitPrice = 32m,
                    PricingRuleId = (long?)null,
                    PricingRuleCode = (string?)null,
                    PricingSourceCode = "MANUAL",
                    DiscountAmount = 0m,
                    DiscountPercent = 0m,
                    DiscountOverrideId = (long?)null,
                    DiscountSourceCode = "NONE",
                    TaxCode = "VAT14",
                    LineNetAmount = 800m,
                    LineTaxAmount = 112m,
                    LineTotalAmount = 912m
                },
                new
                {
                    Id = 2L,
                    SalesOrderId = 1L,
                    LineNumber = 2,
                    ItemId = 1002L,
                    WarehouseId = 1L,
                    OrderedQuantity = 45m,
                    AllocatedQuantity = 0m,
                    DeliveredQuantity = 0m,
                    UnitOfMeasureCode = "BOX",
                    UnitPrice = 50m,
                    BaseUnitPrice = 50m,
                    PricingRuleId = (long?)null,
                    PricingRuleCode = (string?)null,
                    PricingSourceCode = "MANUAL",
                    DiscountAmount = 0m,
                    DiscountPercent = 0m,
                    DiscountOverrideId = (long?)null,
                    DiscountSourceCode = "NONE",
                    TaxCode = "VAT14",
                    LineNetAmount = 2250m,
                    LineTaxAmount = 315m,
                    LineTotalAmount = 2565m
                });
        });

        modelBuilder.Entity<SalesDiscountOverride>(builder =>
        {
            builder.ToTable("so_discount_override");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("so_discount_override_id");
            builder.Property(entry => entry.OverrideNumber).HasColumnName("override_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.SalesOrderId).HasColumnName("so_id");
            builder.Property(entry => entry.SalesOrderLineId).HasColumnName("so_ln_id");
            builder.Property(entry => entry.BaseUnitPrice).HasColumnName("base_unit_price").HasPrecision(18, 2);
            builder.Property(entry => entry.RequestedUnitPrice).HasColumnName("requested_unit_price").HasPrecision(18, 2);
            builder.Property(entry => entry.RequestedDiscountAmount).HasColumnName("requested_discount_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.RequestedDiscountPercent).HasColumnName("requested_discount_pct").HasPrecision(9, 4);
            builder.Property(entry => entry.ReasonCode).HasColumnName("reason_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(entry => entry.StatusId).HasColumnName("status_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.DecidedAtUtc).HasColumnName("decided_at");
            builder.Property(entry => entry.DecidedByUserId).HasColumnName("decided_by");
            builder.Property(entry => entry.DecisionCode).HasColumnName("decision_code").HasMaxLength(30);
            builder.Property(entry => entry.DecisionNotes).HasColumnName("decision_notes").HasMaxLength(1000);
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<SalesReturn>(builder =>
        {
            builder.ToTable("so_rtn_hdr");
            builder.HasKey(salesReturn => salesReturn.Id);
            builder.Property(salesReturn => salesReturn.Id).HasColumnName("so_rtn_id");
            builder.Property(salesReturn => salesReturn.SalesReturnNumber).HasColumnName("so_rtn_no").HasMaxLength(60).IsRequired();
            builder.Property(salesReturn => salesReturn.BranchId).HasColumnName("branch_id");
            builder.Property(salesReturn => salesReturn.CustomerId).HasColumnName("customer_id");
            builder.Property(salesReturn => salesReturn.SalesOrderId).HasColumnName("so_id");
            builder.Property(salesReturn => salesReturn.DispatchOrderId).HasColumnName("dsp_id");
            builder.Property(salesReturn => salesReturn.ReturnDate).HasColumnName("return_date");
            builder.Property(salesReturn => salesReturn.ReturnWarehouseId).HasColumnName("return_wh_id");
            builder.Property(salesReturn => salesReturn.ReasonCode).HasColumnName("reason_code").HasMaxLength(60).IsRequired();
            builder.Property(salesReturn => salesReturn.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(salesReturn => salesReturn.StatusId).HasColumnName("status_id");
            builder.Property(salesReturn => salesReturn.TotalReturnedQuantity).HasColumnName("total_return_qty").HasPrecision(18, 4);
            builder.Property(salesReturn => salesReturn.CreditNoteInvoiceId).HasColumnName("credit_note_ar_inv_id");
            builder.Property(salesReturn => salesReturn.CreditNoteIssuedAtUtc).HasColumnName("credit_note_issued_at");
            builder.Property(salesReturn => salesReturn.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(salesReturn => salesReturn.CreatedByUserId).HasColumnName("created_by");
            builder.Property(salesReturn => salesReturn.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(salesReturn => salesReturn.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(salesReturn => salesReturn.Lines)
                .WithOne()
                .HasForeignKey(line => line.SalesReturnId);
        });

        modelBuilder.Entity<SalesReturnLine>(builder =>
        {
            builder.ToTable("so_rtn_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("so_rtn_ln_id");
            builder.Property(line => line.SalesReturnId).HasColumnName("so_rtn_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.DispatchOrderLineId).HasColumnName("dsp_ln_id");
            builder.Property(line => line.SalesOrderLineId).HasColumnName("so_ln_id");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.QuantityReturned).HasColumnName("qty_returned").HasPrecision(18, 4);
            builder.Property(line => line.WarehouseLocationId).HasColumnName("wh_loc_id");
            builder.Property(line => line.BatchNumber).HasColumnName("batch_no").HasMaxLength(80);
            builder.Property(line => line.SerialNumber).HasColumnName("serial_no").HasMaxLength(120);
            builder.Property(line => line.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
        });

        modelBuilder.Entity<DispatchOrder>(builder =>
        {
            builder.ToTable("dsp_hdr");
            builder.HasKey(dispatch => dispatch.Id);
            builder.Property(dispatch => dispatch.Id).HasColumnName("dsp_id");
            builder.Property(dispatch => dispatch.DispatchNumber).HasColumnName("dsp_no").HasMaxLength(60).IsRequired();
            builder.Property(dispatch => dispatch.BranchId).HasColumnName("branch_id");
            builder.Property(dispatch => dispatch.SalesOrderId).HasColumnName("so_id");
            builder.Property(dispatch => dispatch.DispatchWarehouseId).HasColumnName("dispatch_wh_id");
            builder.Property(dispatch => dispatch.StatusId).HasColumnName("status_id");
            builder.Property(dispatch => dispatch.PlannedShipAtUtc).HasColumnName("planned_ship_at");
            builder.Property(dispatch => dispatch.ShippedAtUtc).HasColumnName("shipped_at");
            builder.Property(dispatch => dispatch.DeliveredAtUtc).HasColumnName("delivered_at");
            builder.Property(dispatch => dispatch.ProofOfDeliveryReceiver).HasColumnName("pod_receiver").HasMaxLength(200);
            builder.Property(dispatch => dispatch.ProofOfDeliveryCapturedAtUtc).HasColumnName("pod_captured_at");
            builder.Property(dispatch => dispatch.ProofOfDeliveryCapturedByUserId).HasColumnName("pod_captured_by");
            builder.Property(dispatch => dispatch.DeliveryConditionCode).HasColumnName("delivery_condition_code").HasMaxLength(30);
            builder.Property(dispatch => dispatch.ProofOfDeliveryReference).HasColumnName("pod_reference").HasMaxLength(120);
            builder.Property(dispatch => dispatch.ProofOfDeliveryNotes).HasColumnName("pod_notes_txt").HasMaxLength(1000);
            builder.Property(dispatch => dispatch.DeliveryExceptionCode).HasColumnName("delivery_exception_code").HasMaxLength(40);
            builder.Property(dispatch => dispatch.DeliveryExceptionRecordedAtUtc).HasColumnName("delivery_exception_at");
            builder.Property(dispatch => dispatch.DeliveryExceptionRecordedByUserId).HasColumnName("delivery_exception_by");
            builder.Property(dispatch => dispatch.DeliveryExceptionNotes).HasColumnName("delivery_exception_notes_txt").HasMaxLength(1000);
            builder.Property(dispatch => dispatch.DeliveryRecoveryStatusCode).HasColumnName("delivery_recovery_status_code").HasMaxLength(30);
            builder.Property(dispatch => dispatch.DeliveryRecoveredAtUtc).HasColumnName("delivery_recovered_at");
            builder.Property(dispatch => dispatch.DeliveryRecoveredByUserId).HasColumnName("delivery_recovered_by");
            builder.Property(dispatch => dispatch.DeliveryRecoveryNotes).HasColumnName("delivery_recovery_notes_txt").HasMaxLength(1000);
            builder.Property(dispatch => dispatch.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(dispatch => dispatch.CreatedByUserId).HasColumnName("created_by");
            builder.Property(dispatch => dispatch.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(dispatch => dispatch.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(dispatch => dispatch.Lines)
                .WithOne()
                .HasForeignKey(line => line.DispatchOrderId);

            builder.HasData(new
            {
                Id = 1L,
                DispatchNumber = "DSP-000001",
                BranchId = 1L,
                SalesOrderId = 1L,
                DispatchWarehouseId = 1L,
                StatusId = WorkflowStatusSeedIds.Draft,
                PlannedShipAtUtc = SeedSubmittedAtUtc.AddDays(3),
                ShippedAtUtc = (DateTime?)null,
                DeliveredAtUtc = (DateTime?)null,
                ProofOfDeliveryReceiver = (string?)null,
                ProofOfDeliveryCapturedAtUtc = (DateTime?)null,
                ProofOfDeliveryCapturedByUserId = (long?)null,
                DeliveryConditionCode = (string?)null,
                ProofOfDeliveryReference = (string?)null,
                ProofOfDeliveryNotes = (string?)null,
                DeliveryExceptionCode = (string?)null,
                DeliveryExceptionRecordedAtUtc = (DateTime?)null,
                DeliveryExceptionRecordedByUserId = (long?)null,
                DeliveryExceptionNotes = (string?)null,
                DeliveryRecoveryStatusCode = (string?)null,
                DeliveryRecoveredAtUtc = (DateTime?)null,
                DeliveryRecoveredByUserId = (long?)null,
                DeliveryRecoveryNotes = (string?)null,
                CreatedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                CreatedByUserId = 2L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<DispatchOrderLine>(builder =>
        {
            builder.ToTable("dsp_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("dsp_ln_id");
            builder.Property(line => line.DispatchOrderId).HasColumnName("dsp_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.SalesOrderLineId).HasColumnName("so_ln_id");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.QuantityDispatched).HasColumnName("qty_dispatched").HasPrecision(18, 4);
            builder.Property(line => line.QuantityDelivered).HasColumnName("qty_delivered").HasPrecision(18, 4);
            builder.Property(line => line.QuantityFailed).HasColumnName("qty_failed").HasPrecision(18, 4);
            builder.Property(line => line.QuantityRecovered).HasColumnName("qty_recovered").HasPrecision(18, 4);
            builder.Property(line => line.WarehouseLocationId).HasColumnName("wh_loc_id");
            builder.Property(line => line.BatchNumber).HasColumnName("batch_no").HasMaxLength(60);
            builder.Property(line => line.SerialNumber).HasColumnName("serial_no").HasMaxLength(100);

            builder.HasData(
                new
                {
                    Id = 1L,
                    DispatchOrderId = 1L,
                    LineNumber = 1,
                    SalesOrderLineId = 1L,
                    ItemId = 1001L,
                    QuantityDispatched = 10m,
                    QuantityDelivered = 0m,
                    QuantityFailed = 0m,
                    QuantityRecovered = 0m,
                    WarehouseLocationId = (long?)null,
                    BatchNumber = "BATCH-1001-A",
                    SerialNumber = (string?)null
                },
                new
                {
                    Id = 2L,
                    DispatchOrderId = 1L,
                    LineNumber = 2,
                    SalesOrderLineId = 2L,
                    ItemId = 1002L,
                    QuantityDispatched = 20m,
                    QuantityDelivered = 0m,
                    QuantityFailed = 0m,
                    QuantityRecovered = 0m,
                    WarehouseLocationId = (long?)null,
                    BatchNumber = "BATCH-1002-A",
                    SerialNumber = (string?)null
                });
        });
    }

    private static void ConfigurePricing(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<PricingRule>(builder =>
        {
            builder.ToTable("so_price_rule_hdr");
            builder.HasKey(rule => rule.Id);
            builder.Property(rule => rule.Id).HasColumnName("price_rule_id");
            builder.Property(rule => rule.RuleCode).HasColumnName("price_rule_code").HasMaxLength(60).IsRequired();
            builder.Property(rule => rule.RuleName).HasColumnName("price_rule_name").HasMaxLength(200).IsRequired();
            builder.Property(rule => rule.BranchId).HasColumnName("branch_id");
            builder.Property(rule => rule.CustomerId).HasColumnName("customer_id");
            builder.Property(rule => rule.ItemId).HasColumnName("item_id");
            builder.Property(rule => rule.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(rule => rule.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(rule => rule.MinimumQuantity).HasColumnName("min_qty").HasPrecision(18, 4);
            builder.Property(rule => rule.MaximumQuantity).HasColumnName("max_qty").HasPrecision(18, 4);
            builder.Property(rule => rule.FixedUnitPrice).HasColumnName("fixed_unit_price").HasPrecision(18, 2);
            builder.Property(rule => rule.Priority).HasColumnName("priority");
            builder.Property(rule => rule.EffectiveFromDate).HasColumnName("effective_from_date");
            builder.Property(rule => rule.EffectiveToDate).HasColumnName("effective_to_date");
            builder.Property(rule => rule.StatusId).HasColumnName("status_id");
            builder.Property(rule => rule.IsActive).HasColumnName("is_active");
            builder.Property(rule => rule.Notes).HasColumnName("notes").HasMaxLength(1000);
            builder.Property(rule => rule.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(rule => rule.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(rule => rule.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(rule => rule.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(rule => rule.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(rule => rule.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(rule => rule.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(rule => rule.CreatedByUserId).HasColumnName("created_by");
            builder.Property(rule => rule.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(rule => rule.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureReceivables(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AccountsReceivableInvoice>(builder =>
        {
            builder.ToTable("ar_inv_hdr");
            builder.HasKey(invoice => invoice.Id);
            builder.Property(invoice => invoice.Id).HasColumnName("ar_inv_id");
            builder.Property(invoice => invoice.InvoiceNumber).HasColumnName("inv_no").HasMaxLength(60).IsRequired();
            builder.Property(invoice => invoice.CustomerId).HasColumnName("customer_id");
            builder.Property(invoice => invoice.SalesOrderId).HasColumnName("so_id");
            builder.Property(invoice => invoice.DispatchOrderId).HasColumnName("dsp_id");
            builder.Property(invoice => invoice.InvoiceType).HasColumnName("inv_type").HasMaxLength(30).IsRequired();
            builder.Property(invoice => invoice.InvoiceDate).HasColumnName("inv_date");
            builder.Property(invoice => invoice.TaxDate).HasColumnName("tax_date");
            builder.Property(invoice => invoice.DueDate).HasColumnName("due_date");
            builder.Property(invoice => invoice.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(invoice => invoice.StatusId).HasColumnName("status_id");
            builder.Property(invoice => invoice.SubtotalAmount).HasColumnName("subtotal_amt").HasPrecision(18, 2);
            builder.Property(invoice => invoice.TaxAmount).HasColumnName("tax_amt").HasPrecision(18, 2);
            builder.Property(invoice => invoice.TotalAmount).HasColumnName("total_amt").HasPrecision(18, 2);
            builder.Property(invoice => invoice.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(invoice => invoice.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(invoice => invoice.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(invoice => invoice.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(invoice => invoice.EtaUuid).HasColumnName("eta_uuid").HasMaxLength(120);
            builder.Property(invoice => invoice.EtaStatus).HasColumnName("eta_status").HasMaxLength(30);
            builder.Property(invoice => invoice.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(invoice => invoice.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(invoice => invoice.CreatedByUserId).HasColumnName("created_by");
            builder.Property(invoice => invoice.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(invoice => invoice.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(invoice => invoice.Lines)
                .WithOne()
                .HasForeignKey(line => line.AccountsReceivableInvoiceId);

            builder.HasData(new
            {
                Id = 1L,
                InvoiceNumber = "ARINV-000001",
                CustomerId = 2L,
                SalesOrderId = 1L,
                DispatchOrderId = (long?)null,
                InvoiceType = "TAX",
                InvoiceDate = new DateOnly(2026, 4, 6),
                TaxDate = new DateOnly(2026, 4, 6),
                DueDate = new DateOnly(2026, 4, 20),
                CurrencyCode = "EGP",
                StatusId = WorkflowStatusSeedIds.Submitted,
                SubtotalAmount = 1300m,
                TaxAmount = 182m,
                TotalAmount = 1482m,
                SubmittedAtUtc = SeedSubmittedAtUtc.AddDays(3),
                SubmittedByUserId = 2L,
                ApprovedAtUtc = (DateTime?)null,
                ApprovedByUserId = (long?)null,
                EtaUuid = (string?)null,
                EtaStatus = "PENDING",
                GeneralLedgerBatchId = (long?)null,
                CreatedAtUtc = SeedSubmittedAtUtc.AddDays(3),
                CreatedByUserId = 2L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<AccountsReceivableInvoiceLine>(builder =>
        {
            builder.ToTable("ar_inv_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("ar_inv_ln_id");
            builder.Property(line => line.AccountsReceivableInvoiceId).HasColumnName("ar_inv_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.SalesOrderLineId).HasColumnName("so_ln_id");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.QuantityInvoiced).HasColumnName("qty_invoiced").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.UnitPrice).HasColumnName("unit_price").HasPrecision(18, 2);
            builder.Property(line => line.TaxCode).HasColumnName("tax_code").HasMaxLength(30);
            builder.Property(line => line.LineNetAmount).HasColumnName("line_net_amt").HasPrecision(18, 2);
            builder.Property(line => line.LineTaxAmount).HasColumnName("line_tax_amt").HasPrecision(18, 2);
            builder.Property(line => line.LineTotalAmount).HasColumnName("line_total_amt").HasPrecision(18, 2);

            builder.HasData(
                new
                {
                    Id = 1L,
                    AccountsReceivableInvoiceId = 1L,
                    LineNumber = 1,
                    SalesOrderLineId = 1L,
                    ItemId = 1001L,
                    QuantityInvoiced = 10m,
                    UnitOfMeasureCode = "EA",
                    UnitPrice = 32m,
                    TaxCode = "VAT14",
                    LineNetAmount = 320m,
                    LineTaxAmount = 44.8m,
                    LineTotalAmount = 364.8m
                },
                new
                {
                    Id = 2L,
                    AccountsReceivableInvoiceId = 1L,
                    LineNumber = 2,
                    SalesOrderLineId = 2L,
                    ItemId = 1002L,
                    QuantityInvoiced = 20m,
                    UnitOfMeasureCode = "BOX",
                    UnitPrice = 49m,
                    TaxCode = "VAT14",
                    LineNetAmount = 980m,
                    LineTaxAmount = 137.2m,
                    LineTotalAmount = 1117.2m
                });
        });

        modelBuilder.Entity<AccountsReceivableReceipt>(builder =>
        {
            builder.ToTable("ar_rcpt_hdr");
            builder.HasKey(receipt => receipt.Id);
            builder.Property(receipt => receipt.Id).HasColumnName("ar_rcpt_id");
            builder.Property(receipt => receipt.ReceiptNumber).HasColumnName("rcpt_no").HasMaxLength(60).IsRequired();
            builder.Property(receipt => receipt.CustomerId).HasColumnName("customer_id");
            builder.Property(receipt => receipt.ReceiptDate).HasColumnName("rcpt_date");
            builder.Property(receipt => receipt.ReceiptMethod).HasColumnName("receipt_method").HasMaxLength(30).IsRequired();
            builder.Property(receipt => receipt.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(receipt => receipt.StatusId).HasColumnName("status_id");
            builder.Property(receipt => receipt.AmountAmount).HasColumnName("amount_amt").HasPrecision(18, 2);
            builder.Property(receipt => receipt.UnappliedAmount).HasColumnName("unapplied_amt").HasPrecision(18, 2);
            builder.Property(receipt => receipt.ReferenceNumber).HasColumnName("reference_no").HasMaxLength(120);
            builder.Property(receipt => receipt.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(receipt => receipt.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(receipt => receipt.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(receipt => receipt.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(receipt => receipt.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(receipt => receipt.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(receipt => receipt.PostedByUserId).HasColumnName("posted_by");
            builder.Property(receipt => receipt.ReversalDate).HasColumnName("reversal_date");
            builder.Property(receipt => receipt.ReversedAtUtc).HasColumnName("reversed_at");
            builder.Property(receipt => receipt.ReversedByUserId).HasColumnName("reversed_by");
            builder.Property(receipt => receipt.ReversalReasonCode).HasColumnName("reversal_reason_code").HasMaxLength(60);
            builder.Property(receipt => receipt.ReversalNotes).HasColumnName("reversal_notes_txt").HasMaxLength(1000);
            builder.Property(receipt => receipt.ReversalGeneralLedgerBatchId).HasColumnName("reversal_gl_batch_id");
            builder.Property(receipt => receipt.ReallocatedFromReceiptId).HasColumnName("reallocated_from_ar_rcpt_id");
            builder.Property(receipt => receipt.ReallocationReceiptId).HasColumnName("reallocation_ar_rcpt_id");
            builder.Property(receipt => receipt.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(receipt => receipt.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(receipt => receipt.CreatedByUserId).HasColumnName("created_by");
            builder.Property(receipt => receipt.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(receipt => receipt.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(receipt => receipt.Allocations)
                .WithOne()
                .HasForeignKey(allocation => allocation.AccountsReceivableReceiptId);

            builder.HasData(new
            {
                Id = 1L,
                ReceiptNumber = "ARRCPT-000001",
                CustomerId = 2L,
                ReceiptDate = new DateOnly(2026, 4, 7),
                ReceiptMethod = "BANK_TRANSFER",
                CurrencyCode = "EGP",
                StatusId = WorkflowStatusSeedIds.Submitted,
                AmountAmount = 1000m,
                UnappliedAmount = 200m,
                ReferenceNumber = "BANK-REF-0001",
                Notes = "Customer partial receipt",
                SubmittedAtUtc = SeedSubmittedAtUtc.AddDays(4),
                SubmittedByUserId = 3L,
                ApprovedAtUtc = (DateTime?)null,
                ApprovedByUserId = (long?)null,
                PostedAtUtc = (DateTime?)null,
                PostedByUserId = (long?)null,
                ReversalDate = (DateOnly?)null,
                ReversedAtUtc = (DateTime?)null,
                ReversedByUserId = (long?)null,
                ReversalReasonCode = (string?)null,
                ReversalNotes = (string?)null,
                ReversalGeneralLedgerBatchId = (long?)null,
                ReallocatedFromReceiptId = (long?)null,
                ReallocationReceiptId = (long?)null,
                GeneralLedgerBatchId = (long?)null,
                CreatedAtUtc = SeedSubmittedAtUtc.AddDays(4),
                CreatedByUserId = 3L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<AccountsReceivableReceiptAllocation>(builder =>
        {
            builder.ToTable("ar_rcpt_alloc");
            builder.HasKey(allocation => allocation.Id);
            builder.Property(allocation => allocation.Id).HasColumnName("ar_rcpt_alloc_id");
            builder.Property(allocation => allocation.AccountsReceivableReceiptId).HasColumnName("ar_rcpt_id");
            builder.Property(allocation => allocation.AccountsReceivableInvoiceId).HasColumnName("ar_inv_id");
            builder.Property(allocation => allocation.AllocationAmount).HasColumnName("alloc_amt").HasPrecision(18, 2);
            builder.Property(allocation => allocation.AllocationDate).HasColumnName("alloc_date");
            builder.Property<DateTime>("CreatedAtUtc").HasColumnName("created_at");
            builder.Property<long?>("CreatedByUserId").HasColumnName("created_by");

            builder.HasData(new
            {
                Id = 1L,
                AccountsReceivableReceiptId = 1L,
                AccountsReceivableInvoiceId = 1L,
                AllocationAmount = 800m,
                AllocationDate = new DateOnly(2026, 4, 7),
                CreatedAtUtc = SeedSubmittedAtUtc.AddDays(4),
                CreatedByUserId = 3L
            });
        });
    }

    private static void ConfigurePayablesPayments(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AccountsPayablePayment>(builder =>
        {
            builder.ToTable("ap_pay_hdr");
            builder.HasKey(payment => payment.Id);
            builder.Property(payment => payment.Id).HasColumnName("ap_pay_id");
            builder.Property(payment => payment.PaymentNumber).HasColumnName("pay_no").HasMaxLength(60).IsRequired();
            builder.Property(payment => payment.SupplierId).HasColumnName("supplier_id");
            builder.Property(payment => payment.PaymentDate).HasColumnName("pay_date");
            builder.Property(payment => payment.PaymentMethod).HasColumnName("payment_method").HasMaxLength(30).IsRequired();
            builder.Property(payment => payment.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(payment => payment.StatusId).HasColumnName("status_id");
            builder.Property(payment => payment.AmountAmount).HasColumnName("amount_amt").HasPrecision(18, 2);
            builder.Property(payment => payment.UnappliedAmount).HasColumnName("unapplied_amt").HasPrecision(18, 2);
            builder.Property(payment => payment.ReferenceNumber).HasColumnName("reference_no").HasMaxLength(120);
            builder.Property(payment => payment.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(payment => payment.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(payment => payment.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(payment => payment.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(payment => payment.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(payment => payment.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(payment => payment.PostedByUserId).HasColumnName("posted_by");
            builder.Property(payment => payment.ReversalDate).HasColumnName("reversal_date");
            builder.Property(payment => payment.ReversedAtUtc).HasColumnName("reversed_at");
            builder.Property(payment => payment.ReversedByUserId).HasColumnName("reversed_by");
            builder.Property(payment => payment.ReversalReasonCode).HasColumnName("reversal_reason_code").HasMaxLength(60);
            builder.Property(payment => payment.ReversalNotes).HasColumnName("reversal_notes_txt").HasMaxLength(1000);
            builder.Property(payment => payment.ReversalGeneralLedgerBatchId).HasColumnName("reversal_gl_batch_id");
            builder.Property(payment => payment.RepostedFromPaymentId).HasColumnName("reposted_from_ap_pay_id");
            builder.Property(payment => payment.RepostPaymentId).HasColumnName("repost_ap_pay_id");
            builder.Property(payment => payment.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(payment => payment.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(payment => payment.CreatedByUserId).HasColumnName("created_by");
            builder.Property(payment => payment.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(payment => payment.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(payment => payment.Allocations)
                .WithOne()
                .HasForeignKey(allocation => allocation.AccountsPayablePaymentId);
        });

        modelBuilder.Entity<AccountsPayablePaymentAllocation>(builder =>
        {
            builder.ToTable("ap_pay_alloc");
            builder.HasKey(allocation => allocation.Id);
            builder.Property(allocation => allocation.Id).HasColumnName("ap_pay_alloc_id");
            builder.Property(allocation => allocation.AccountsPayablePaymentId).HasColumnName("ap_pay_id");
            builder.Property(allocation => allocation.AccountsPayableBillId).HasColumnName("ap_bill_id");
            builder.Property(allocation => allocation.AllocationAmount).HasColumnName("alloc_amt").HasPrecision(18, 2);
            builder.Property(allocation => allocation.AllocationDate).HasColumnName("alloc_date");
        });
    }

    private static void ConfigureCustomerPaymentRequests(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<CustomerPaymentRequest>(builder =>
        {
            builder.ToTable("ar_pay_req_hdr");
            builder.HasKey(request => request.Id);
            builder.Property(request => request.Id).HasColumnName("ar_pay_req_id");
            builder.Property(request => request.PaymentRequestNumber).HasColumnName("pay_req_no").HasMaxLength(60).IsRequired();
            builder.Property(request => request.CustomerId).HasColumnName("customer_id");
            builder.Property(request => request.AccountsReceivableInvoiceId).HasColumnName("ar_inv_id");
            builder.Property(request => request.PaymentChannelConfigurationId).HasColumnName("pay_channel_cfg_id");
            builder.Property(request => request.PaymentDate).HasColumnName("payment_date");
            builder.Property(request => request.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(request => request.AmountAmount).HasColumnName("amount_amt").HasPrecision(18, 2);
            builder.Property(request => request.StatusCode).HasColumnName("status_code").HasMaxLength(40).IsRequired();
            builder.Property(request => request.ReferenceNumber).HasColumnName("reference_no").HasMaxLength(120);
            builder.Property(request => request.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(request => request.CorrelationKey).HasColumnName("correlation_key").HasMaxLength(120);
            builder.Property(request => request.SettledAccountsReceivableReceiptId).HasColumnName("settled_ar_rcpt_id");
            builder.Property(request => request.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(request => request.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(request => request.CompletedAtUtc).HasColumnName("completed_at");
            builder.Property(request => request.LastErrorText).HasColumnName("last_error_txt").HasMaxLength(1000);
            builder.Property(request => request.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(request => request.CreatedByUserId).HasColumnName("created_by");
            builder.Property(request => request.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(request => request.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureCustomerRefunds(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<CustomerRefund>(builder =>
        {
            builder.ToTable("ar_refund_hdr");
            builder.HasKey(refund => refund.Id);
            builder.Property(refund => refund.Id).HasColumnName("ar_refund_id");
            builder.Property(refund => refund.RefundNumber).HasColumnName("refund_no").HasMaxLength(60).IsRequired();
            builder.Property(refund => refund.CustomerId).HasColumnName("customer_id");
            builder.Property(refund => refund.SourceAccountsReceivableReceiptId).HasColumnName("src_ar_rcpt_id");
            builder.Property(refund => refund.RefundDate).HasColumnName("refund_date");
            builder.Property(refund => refund.RefundMethod).HasColumnName("refund_method").HasMaxLength(30).IsRequired();
            builder.Property(refund => refund.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(refund => refund.AmountAmount).HasColumnName("amount_amt").HasPrecision(18, 2);
            builder.Property(refund => refund.PaymentChannelConfigurationId).HasColumnName("pay_channel_cfg_id");
            builder.Property(refund => refund.ReferenceNumber).HasColumnName("reference_no").HasMaxLength(120);
            builder.Property(refund => refund.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(refund => refund.StatusId).HasColumnName("status_id");
            builder.Property(refund => refund.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(refund => refund.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(refund => refund.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(refund => refund.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(refund => refund.ReturnedAtUtc).HasColumnName("returned_at");
            builder.Property(refund => refund.ReturnedByUserId).HasColumnName("returned_by");
            builder.Property(refund => refund.ReturnNotes).HasColumnName("return_notes_txt").HasMaxLength(1000);
            builder.Property(refund => refund.RejectedAtUtc).HasColumnName("rejected_at");
            builder.Property(refund => refund.RejectedByUserId).HasColumnName("rejected_by");
            builder.Property(refund => refund.RejectionNotes).HasColumnName("rejection_notes_txt").HasMaxLength(1000);
            builder.Property(refund => refund.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(refund => refund.PostedByUserId).HasColumnName("posted_by");
            builder.Property(refund => refund.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(refund => refund.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(refund => refund.CreatedByUserId).HasColumnName("created_by");
            builder.Property(refund => refund.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(refund => refund.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<PaymentGatewayExecution>(builder =>
        {
            builder.ToTable("pay_gateway_exec");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("pay_gateway_exec_id");
            builder.Property(entry => entry.ExecutionNumber).HasColumnName("exec_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.PaymentChannelConfigurationId).HasColumnName("pay_channel_cfg_id");
            builder.Property(entry => entry.IntegrationEndpointId).HasColumnName("int_endpoint_reg_id");
            builder.Property(entry => entry.SourceDocumentType).HasColumnName("src_doc_type").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.SourceDocumentId).HasColumnName("src_doc_id");
            builder.Property(entry => entry.SourceDocumentNumber).HasColumnName("src_doc_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.PartyId).HasColumnName("party_id");
            builder.Property(entry => entry.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.AmountAmount).HasColumnName("amount_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.CorrelationKey).HasColumnName("correlation_key").HasMaxLength(120).IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.ProviderReference).HasColumnName("provider_ref").HasMaxLength(120);
            builder.Property(entry => entry.ProviderStatusCode).HasColumnName("provider_status_code").HasMaxLength(40);
            builder.Property(entry => entry.ProviderResponseText).HasColumnName("provider_response_txt");
            builder.Property(entry => entry.AttemptNumber).HasColumnName("attempt_no");
            builder.Property(entry => entry.DispatchedAtUtc).HasColumnName("dispatched_at");
            builder.Property(entry => entry.DispatchedByProcess).HasColumnName("dispatched_by_process").HasMaxLength(60);
            builder.Property(entry => entry.CompletedAtUtc).HasColumnName("completed_at");
            builder.Property(entry => entry.LastErrorText).HasColumnName("last_error_txt").HasMaxLength(1000);
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureBankTransferBatches(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<BankTransferBatch>(builder =>
        {
            builder.ToTable("ap_pay_batch_hdr");
            builder.HasKey(batch => batch.Id);
            builder.Property(batch => batch.Id).HasColumnName("ap_pay_batch_id");
            builder.Property(batch => batch.BatchNumber).HasColumnName("batch_no").HasMaxLength(60).IsRequired();
            builder.Property(batch => batch.BankAccountCode).HasColumnName("bank_acct_code").HasMaxLength(60).IsRequired();
            builder.Property(batch => batch.TransferDate).HasColumnName("transfer_date");
            builder.Property(batch => batch.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(batch => batch.StatusId).HasColumnName("status_id");
            builder.Property(batch => batch.TotalPaymentCount).HasColumnName("total_payment_count");
            builder.Property(batch => batch.TotalAmount).HasColumnName("total_amount").HasPrecision(18, 2);
            builder.Property(batch => batch.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(batch => batch.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(batch => batch.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(batch => batch.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(batch => batch.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(batch => batch.PostedByUserId).HasColumnName("posted_by");
            builder.Property(batch => batch.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(batch => batch.CreatedByUserId).HasColumnName("created_by");
            builder.Property(batch => batch.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(batch => batch.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(batch => batch.Lines)
                .WithOne()
                .HasForeignKey(line => line.BankTransferBatchId);
        });

        modelBuilder.Entity<BankTransferBatchLine>(builder =>
        {
            builder.ToTable("ap_pay_batch_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("ap_pay_batch_ln_id");
            builder.Property(line => line.BankTransferBatchId).HasColumnName("ap_pay_batch_id");
            builder.Property(line => line.AccountsPayablePaymentId).HasColumnName("ap_pay_id");
            builder.Property(line => line.PaymentNumber).HasColumnName("pay_no").HasMaxLength(60).IsRequired();
            builder.Property(line => line.SupplierId).HasColumnName("supplier_id");
            builder.Property(line => line.AmountAmount).HasColumnName("amount_amt").HasPrecision(18, 2);
        });
    }

    private static void ConfigurePaymentSettlementBatches(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<PaymentSettlementBatch>(builder =>
        {
            builder.ToTable("pay_settle_batch_hdr");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("pay_settle_batch_id");
            builder.Property(entry => entry.BatchNumber).HasColumnName("batch_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.PaymentChannelConfigurationId).HasColumnName("pay_channel_cfg_id");
            builder.Property(entry => entry.SettlementDate).HasColumnName("settlement_date");
            builder.Property(entry => entry.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.ExternalBatchReference).HasColumnName("ext_batch_ref").HasMaxLength(120);
            builder.Property(entry => entry.StatusId).HasColumnName("status_id");
            builder.Property(entry => entry.TotalTransactionCount).HasColumnName("total_txn_count");
            builder.Property(entry => entry.TotalInternalAmount).HasColumnName("total_internal_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.TotalSettledAmount).HasColumnName("total_settled_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.TotalFeeAmount).HasColumnName("total_fee_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.TotalNetAmount).HasColumnName("total_net_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.OpenExceptionCount).HasColumnName("open_excp_count");
            builder.Property(entry => entry.ResolvedExceptionCount).HasColumnName("resolved_excp_count");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(entry => entry.PostedByUserId).HasColumnName("posted_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(entry => entry.Lines)
                .WithOne()
                .HasForeignKey(line => line.PaymentSettlementBatchId);

            builder.HasMany(entry => entry.Exceptions)
                .WithOne()
                .HasForeignKey(exception => exception.PaymentSettlementBatchId);
        });

        modelBuilder.Entity<PaymentSettlementBatchLine>(builder =>
        {
            builder.ToTable("pay_settle_batch_ln");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("pay_settle_batch_ln_id");
            builder.Property(entry => entry.PaymentSettlementBatchId).HasColumnName("pay_settle_batch_id");
            builder.Property(entry => entry.SourceDocumentType).HasColumnName("src_doc_type").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.SourceDocumentId).HasColumnName("src_doc_id");
            builder.Property(entry => entry.SourceDocumentNumber).HasColumnName("src_doc_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.PartyId).HasColumnName("party_id");
            builder.Property(entry => entry.InternalAmount).HasColumnName("internal_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.SettledAmount).HasColumnName("settled_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.FeeAmount).HasColumnName("fee_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.NetAmount).HasColumnName("net_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.ProviderReference).HasColumnName("provider_ref").HasMaxLength(120);
            builder.Property(entry => entry.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(entry => entry.SettlementStatusCode).HasColumnName("settlement_status_code").HasMaxLength(30).IsRequired();
        });

        modelBuilder.Entity<PaymentSettlementException>(builder =>
        {
            builder.ToTable("pay_settle_excp");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("pay_settle_excp_id");
            builder.Property(entry => entry.PaymentSettlementBatchId).HasColumnName("pay_settle_batch_id");
            builder.Property(entry => entry.PaymentSettlementBatchLineId).HasColumnName("pay_settle_batch_ln_id");
            builder.Property(entry => entry.SourceDocumentType).HasColumnName("src_doc_type").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.SourceDocumentId).HasColumnName("src_doc_id");
            builder.Property(entry => entry.SourceDocumentNumber).HasColumnName("src_doc_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.PartyId).HasColumnName("party_id");
            builder.Property(entry => entry.ExceptionCode).HasColumnName("exception_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(20).IsRequired();
            builder.Property(entry => entry.DifferenceAmount).HasColumnName("difference_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(entry => entry.ResolutionCode).HasColumnName("resolution_code").HasMaxLength(30);
            builder.Property(entry => entry.ResolvedAtUtc).HasColumnName("resolved_at");
            builder.Property(entry => entry.ResolvedByUserId).HasColumnName("resolved_by");
        });
    }

    private static void ConfigureTreasury(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<CashAccount>(builder =>
        {
            builder.ToTable("cash_acct");
            builder.HasKey(account => account.Id);
            builder.Property(account => account.Id).HasColumnName("cash_acct_id");
            builder.Property(account => account.AccountCode).HasColumnName("acct_code").HasMaxLength(60).IsRequired();
            builder.Property(account => account.AccountName).HasColumnName("acct_name").HasMaxLength(200).IsRequired();
            builder.Property(account => account.AccountType).HasColumnName("acct_type").HasMaxLength(30).IsRequired();
            builder.Property(account => account.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(account => account.BranchId).HasColumnName("branch_id");
            builder.Property(account => account.IsActive).HasColumnName("is_active");
            builder.Property(account => account.OpeningBalanceAmount).HasColumnName("opening_balance_amt").HasPrecision(18, 2);
            builder.Property(account => account.CurrentBalanceAmount).HasColumnName("current_balance_amt").HasPrecision(18, 2);
            builder.Property(account => account.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(account => account.CreatedByUserId).HasColumnName("created_by");
            builder.Property(account => account.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(account => account.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasData(
                new
                {
                    Id = 1L,
                    AccountCode = "CASH-EGP-001",
                    AccountName = "Main Cash Desk",
                    AccountType = "CASH",
                    CurrencyCode = "EGP",
                    BranchId = 1L,
                    IsActive = true,
                    OpeningBalanceAmount = 5000m,
                    CurrentBalanceAmount = 5000m,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                },
                new
                {
                    Id = 2L,
                    AccountCode = "BANK-EGP-001",
                    AccountName = "Main EGP Bank Account",
                    AccountType = "BANK",
                    CurrencyCode = "EGP",
                    BranchId = 1L,
                    IsActive = true,
                    OpeningBalanceAmount = 25000m,
                    CurrentBalanceAmount = 25000m,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = (long?)null,
                    UpdatedAtUtc = (DateTime?)null,
                    UpdatedByUserId = (long?)null
                });
        });

        modelBuilder.Entity<TreasuryTransfer>(builder =>
        {
            builder.ToTable("treasury_trf_hdr");
            builder.HasKey(transfer => transfer.Id);
            builder.Property(transfer => transfer.Id).HasColumnName("treasury_trf_id");
            builder.Property(transfer => transfer.TransferNumber).HasColumnName("trf_no").HasMaxLength(60).IsRequired();
            builder.Property(transfer => transfer.FromCashAccountId).HasColumnName("from_cash_acct_id");
            builder.Property(transfer => transfer.ToCashAccountId).HasColumnName("to_cash_acct_id");
            builder.Property(transfer => transfer.TransferDate).HasColumnName("trf_date");
            builder.Property(transfer => transfer.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(transfer => transfer.AmountAmount).HasColumnName("amount_amt").HasPrecision(18, 2);
            builder.Property(transfer => transfer.ReferenceNumber).HasColumnName("reference_no").HasMaxLength(120);
            builder.Property(transfer => transfer.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(transfer => transfer.StatusId).HasColumnName("status_id");
            builder.Property(transfer => transfer.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(transfer => transfer.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(transfer => transfer.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(transfer => transfer.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(transfer => transfer.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(transfer => transfer.PostedByUserId).HasColumnName("posted_by");
            builder.Property(transfer => transfer.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(transfer => transfer.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(transfer => transfer.CreatedByUserId).HasColumnName("created_by");
            builder.Property(transfer => transfer.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(transfer => transfer.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureForeignExchangeQuotes(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ForeignExchangeQuote>(builder =>
        {
            builder.ToTable("fx_quote_hist");
            builder.HasKey(quote => quote.Id);
            builder.Property(quote => quote.Id).HasColumnName("fx_quote_id");
            builder.Property(quote => quote.QuoteNumber).HasColumnName("quote_no").HasMaxLength(60).IsRequired();
            builder.Property(quote => quote.IntegrationEndpointId).HasColumnName("int_endpoint_id");
            builder.Property(quote => quote.QuoteDate).HasColumnName("quote_date");
            builder.Property(quote => quote.BaseCurrencyCode).HasColumnName("base_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(quote => quote.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(quote => quote.RateToBase).HasColumnName("rate_to_base").HasPrecision(18, 8);
            builder.Property(quote => quote.SourceBatchReference).HasColumnName("source_batch_ref").HasMaxLength(120);
            builder.Property(quote => quote.ExternalQuoteReference).HasColumnName("external_quote_ref").HasMaxLength(120);
            builder.Property(quote => quote.Notes).HasColumnName("notes").HasMaxLength(1000);
            builder.Property(quote => quote.IngestedAtUtc).HasColumnName("ingested_at");
            builder.Property(quote => quote.IngestedByUserId).HasColumnName("ingested_by");
            builder.Property(quote => quote.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(quote => quote.CreatedByUserId).HasColumnName("created_by");
            builder.Property(quote => quote.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(quote => quote.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(quote => new
            {
                quote.IntegrationEndpointId,
                quote.QuoteDate,
                quote.BaseCurrencyCode,
                quote.CurrencyCode
            }).IsUnique();
        });
    }

    private static void ConfigureForeignExchangeOverrides(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ForeignExchangeOverride>(builder =>
        {
            builder.ToTable("fx_override_hdr");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("fx_override_id");
            builder.Property(entry => entry.OverrideNumber).HasColumnName("override_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.EffectiveDate).HasColumnName("effective_date");
            builder.Property(entry => entry.BaseCurrencyCode).HasColumnName("base_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.OverrideRateToBase).HasColumnName("override_rate_to_base").HasPrecision(18, 8);
            builder.Property(entry => entry.ReasonCode).HasColumnName("reason_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.Notes).HasColumnName("notes").HasMaxLength(1000);
            builder.Property(entry => entry.StatusId).HasColumnName("status_id");
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasIndex(entry => new
            {
                entry.EffectiveDate,
                entry.BaseCurrencyCode,
                entry.CurrencyCode
            }).IsUnique();
        });
    }

    private static void ConfigureForeignExchangeRevaluations(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ForeignExchangeRevaluation>(builder =>
        {
            builder.ToTable("fx_reval_hdr");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("fx_reval_id");
            builder.Property(entry => entry.RevaluationNumber).HasColumnName("reval_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.AccountingPeriodId).HasColumnName("period_id");
            builder.Property(entry => entry.RevaluationDate).HasColumnName("reval_date");
            builder.Property(entry => entry.BaseCurrencyCode).HasColumnName("base_currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.Notes).HasColumnName("notes").HasMaxLength(1000);
            builder.Property(entry => entry.StatusId).HasColumnName("status_id");
            builder.Property(entry => entry.TotalGainBaseAmount).HasColumnName("total_gain_base_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.TotalLossBaseAmount).HasColumnName("total_loss_base_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.NetVarianceBaseAmount).HasColumnName("net_variance_base_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(entry => entry.PostedByUserId).HasColumnName("posted_by");
            builder.Property(entry => entry.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
            builder.HasMany(entry => entry.Lines).WithOne().HasForeignKey(line => line.ForeignExchangeRevaluationId);
        });

        modelBuilder.Entity<ForeignExchangeRevaluationLine>(builder =>
        {
            builder.ToTable("fx_reval_ln");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("fx_reval_ln_id");
            builder.Property(entry => entry.ForeignExchangeRevaluationId).HasColumnName("fx_reval_id");
            builder.Property(entry => entry.LineNumber).HasColumnName("line_no");
            builder.Property(entry => entry.SourceTypeCode).HasColumnName("source_type_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.SourceDocumentId).HasColumnName("source_doc_id");
            builder.Property(entry => entry.SourceDocumentNumber).HasColumnName("source_doc_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.SourceGeneralLedgerAccountId).HasColumnName("source_gl_acct_id");
            builder.Property(entry => entry.BranchId).HasColumnName("branch_id");
            builder.Property(entry => entry.PartyId).HasColumnName("party_id");
            builder.Property(entry => entry.SourceDocumentDate).HasColumnName("source_doc_date");
            builder.Property(entry => entry.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.ForeignAmount).HasColumnName("foreign_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.CarryingRateToBase).HasColumnName("carrying_rate_to_base").HasPrecision(18, 8);
            builder.Property(entry => entry.RevaluationRateToBase).HasColumnName("reval_rate_to_base").HasPrecision(18, 8);
            builder.Property(entry => entry.CarryingBaseAmount).HasColumnName("carrying_base_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.RevaluedBaseAmount).HasColumnName("revalued_base_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.VarianceBaseAmount).HasColumnName("variance_base_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureCollections(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<CollectionsFollowUpAction>(builder =>
        {
            builder.ToTable("ar_coll_act");
            builder.HasKey(action => action.Id);
            builder.Property(action => action.Id).HasColumnName("ar_coll_act_id");
            builder.Property(action => action.AccountsReceivableInvoiceId).HasColumnName("ar_inv_id");
            builder.Property(action => action.CustomerId).HasColumnName("customer_id");
            builder.Property(action => action.ActionDate).HasColumnName("action_date");
            builder.Property(action => action.ActionTypeCode).HasColumnName("action_type_code").HasMaxLength(40).IsRequired();
            builder.Property(action => action.OutcomeCode).HasColumnName("outcome_code").HasMaxLength(40).IsRequired();
            builder.Property(action => action.PromiseToPayDate).HasColumnName("promise_to_pay_date");
            builder.Property(action => action.NextFollowUpDate).HasColumnName("next_follow_up_date");
            builder.Property(action => action.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(action => action.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(action => action.CreatedByUserId).HasColumnName("created_by");
            builder.Property(action => action.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(action => action.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureWalletRules(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<WalletRule>(builder =>
        {
            builder.ToTable("wallet_rule_hdr");
            builder.HasKey(rule => rule.Id);
            builder.Property(rule => rule.Id).HasColumnName("wallet_rule_id");
            builder.Property(rule => rule.RuleCode).HasColumnName("wallet_rule_code").HasMaxLength(60).IsRequired();
            builder.Property(rule => rule.RuleName).HasColumnName("wallet_rule_name").HasMaxLength(200).IsRequired();
            builder.Property(rule => rule.BranchId).HasColumnName("branch_id");
            builder.Property(rule => rule.PartyTypeCode).HasColumnName("party_type_code").HasMaxLength(20).IsRequired();
            builder.Property(rule => rule.TransactionTypeCode).HasColumnName("txn_type_code").HasMaxLength(20).IsRequired();
            builder.Property(rule => rule.WalletSchemeCode).HasColumnName("wallet_scheme_code").HasMaxLength(30).IsRequired();
            builder.Property(rule => rule.IntegrationProviderCode).HasColumnName("provider_code").HasMaxLength(30).IsRequired();
            builder.Property(rule => rule.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(rule => rule.MinimumAmount).HasColumnName("min_amt").HasPrecision(18, 2);
            builder.Property(rule => rule.MaximumAmount).HasColumnName("max_amt").HasPrecision(18, 2);
            builder.Property(rule => rule.SettlementLeadDays).HasColumnName("settlement_lead_days");
            builder.Property(rule => rule.FeePercent).HasColumnName("fee_pct").HasPrecision(9, 4);
            builder.Property(rule => rule.FlatFeeAmount).HasColumnName("flat_fee_amt").HasPrecision(18, 2);
            builder.Property(rule => rule.Priority).HasColumnName("priority");
            builder.Property(rule => rule.EffectiveFromDate).HasColumnName("effective_from_date");
            builder.Property(rule => rule.EffectiveToDate).HasColumnName("effective_to_date");
            builder.Property(rule => rule.StatusId).HasColumnName("status_id");
            builder.Property(rule => rule.IsActive).HasColumnName("is_active");
            builder.Property(rule => rule.Notes).HasColumnName("notes").HasMaxLength(1000);
            builder.Property(rule => rule.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(rule => rule.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(rule => rule.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(rule => rule.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(rule => rule.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(rule => rule.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(rule => rule.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(rule => rule.CreatedByUserId).HasColumnName("created_by");
            builder.Property(rule => rule.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(rule => rule.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureAccountingRules(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<FinanceAccountingRule>(builder =>
        {
            builder.ToTable("fin_acct_rule_hdr");
            builder.HasKey(rule => rule.Id);
            builder.Property(rule => rule.Id).HasColumnName("fin_acct_rule_id");
            builder.Property(rule => rule.RuleCode).HasColumnName("rule_code").HasMaxLength(60).IsRequired();
            builder.Property(rule => rule.RuleName).HasColumnName("rule_name").HasMaxLength(200).IsRequired();
            builder.Property(rule => rule.GeneralLedgerAccountId).HasColumnName("gl_acct_id");
            builder.Property(rule => rule.GeneralLedgerAccountCode).HasColumnName("gl_acct_code").HasMaxLength(30).IsRequired();
            builder.Property(rule => rule.GeneralLedgerAccountName).HasColumnName("gl_acct_name").HasMaxLength(200).IsRequired();
            builder.Property(rule => rule.AccountCategoryCode).HasColumnName("acct_category_code").HasMaxLength(30).IsRequired();
            builder.Property(rule => rule.StatementSectionCode).HasColumnName("statement_section_code").HasMaxLength(40).IsRequired();
            builder.Property(rule => rule.CashFlowCategoryCode).HasColumnName("cash_flow_category_code").HasMaxLength(20).IsRequired();
            builder.Property(rule => rule.IsCashAccount).HasColumnName("is_cash_acct");
            builder.Property(rule => rule.DisplayOrder).HasColumnName("display_order");
            builder.Property(rule => rule.EffectiveFromDate).HasColumnName("effective_from_date");
            builder.Property(rule => rule.EffectiveToDate).HasColumnName("effective_to_date");
            builder.Property(rule => rule.StatusId).HasColumnName("status_id");
            builder.Property(rule => rule.IsActive).HasColumnName("is_active");
            builder.Property(rule => rule.Notes).HasColumnName("notes").HasMaxLength(1000);
            builder.Property(rule => rule.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(rule => rule.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(rule => rule.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(rule => rule.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(rule => rule.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(rule => rule.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(rule => rule.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(rule => rule.CreatedByUserId).HasColumnName("created_by");
            builder.Property(rule => rule.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(rule => rule.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasData(
                new
                {
                    Id = 1L,
                    RuleCode = "ACR-000001",
                    RuleName = "Cash and bank",
                    GeneralLedgerAccountId = 1001L,
                    GeneralLedgerAccountCode = "1001",
                    GeneralLedgerAccountName = "Cash and bank",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Asset,
                    StatementSectionCode = FinanceAccountingRuleCatalog.CurrentAsset,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.OperatingCashFlow,
                    IsCashAccount = true,
                    DisplayOrder = 10,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for cash and bank balances.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                },
                new
                {
                    Id = 2L,
                    RuleCode = "ACR-000002",
                    RuleName = "Accounts receivable",
                    GeneralLedgerAccountId = 1101L,
                    GeneralLedgerAccountCode = "1101",
                    GeneralLedgerAccountName = "Accounts receivable",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Asset,
                    StatementSectionCode = FinanceAccountingRuleCatalog.CurrentAsset,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.OperatingCashFlow,
                    IsCashAccount = false,
                    DisplayOrder = 20,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for customer receivables.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                },
                new
                {
                    Id = 3L,
                    RuleCode = "ACR-000003",
                    RuleName = "Inventory asset",
                    GeneralLedgerAccountId = 1401L,
                    GeneralLedgerAccountCode = "1401",
                    GeneralLedgerAccountName = "Inventory asset",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Asset,
                    StatementSectionCode = FinanceAccountingRuleCatalog.CurrentAsset,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.OperatingCashFlow,
                    IsCashAccount = false,
                    DisplayOrder = 30,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for inventory control balances.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                },
                new
                {
                    Id = 4L,
                    RuleCode = "ACR-000004",
                    RuleName = "Accounts payable",
                    GeneralLedgerAccountId = 2001L,
                    GeneralLedgerAccountCode = "2001",
                    GeneralLedgerAccountName = "Accounts payable",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Liability,
                    StatementSectionCode = FinanceAccountingRuleCatalog.CurrentLiability,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.OperatingCashFlow,
                    IsCashAccount = false,
                    DisplayOrder = 40,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for supplier liabilities.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                },
                new
                {
                    Id = 5L,
                    RuleCode = "ACR-000005",
                    RuleName = "Revenue",
                    GeneralLedgerAccountId = 4001L,
                    GeneralLedgerAccountCode = "4001",
                    GeneralLedgerAccountName = "Revenue",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Revenue,
                    StatementSectionCode = FinanceAccountingRuleCatalog.OperatingRevenue,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.OperatingCashFlow,
                    IsCashAccount = false,
                    DisplayOrder = 50,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for operating revenue.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                },
                new
                {
                    Id = 6L,
                    RuleCode = "ACR-000006",
                    RuleName = "Other operating income",
                    GeneralLedgerAccountId = 4105L,
                    GeneralLedgerAccountCode = "4105",
                    GeneralLedgerAccountName = "Other operating income",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Revenue,
                    StatementSectionCode = FinanceAccountingRuleCatalog.OtherIncome,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.NonCashFlow,
                    IsCashAccount = false,
                    DisplayOrder = 60,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for Murabaha profit and stock gains.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                },
                new
                {
                    Id = 7L,
                    RuleCode = "ACR-000007",
                    RuleName = "FX gain",
                    GeneralLedgerAccountId = 5101L,
                    GeneralLedgerAccountCode = "5101",
                    GeneralLedgerAccountName = "FX gain",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Revenue,
                    StatementSectionCode = FinanceAccountingRuleCatalog.OtherIncome,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.NonCashFlow,
                    IsCashAccount = false,
                    DisplayOrder = 70,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for foreign-exchange gain.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                },
                new
                {
                    Id = 8L,
                    RuleCode = "ACR-000008",
                    RuleName = "Inventory adjustment loss",
                    GeneralLedgerAccountId = 5105L,
                    GeneralLedgerAccountCode = "5105",
                    GeneralLedgerAccountName = "Inventory adjustment loss",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Expense,
                    StatementSectionCode = FinanceAccountingRuleCatalog.OperatingExpense,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.NonCashFlow,
                    IsCashAccount = false,
                    DisplayOrder = 80,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for inventory-adjustment losses.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                },
                new
                {
                    Id = 9L,
                    RuleCode = "ACR-000009",
                    RuleName = "FX loss",
                    GeneralLedgerAccountId = 6101L,
                    GeneralLedgerAccountCode = "6101",
                    GeneralLedgerAccountName = "FX loss",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Expense,
                    StatementSectionCode = FinanceAccountingRuleCatalog.OtherExpense,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.NonCashFlow,
                    IsCashAccount = false,
                    DisplayOrder = 90,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for foreign-exchange loss.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                },
                new
                {
                    Id = 10L,
                    RuleCode = "ACR-000010",
                    RuleName = "Murabaha receivable",
                    GeneralLedgerAccountId = 1105L,
                    GeneralLedgerAccountCode = "1105",
                    GeneralLedgerAccountName = "Murabaha receivable",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Asset,
                    StatementSectionCode = FinanceAccountingRuleCatalog.CurrentAsset,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.FinancingCashFlow,
                    IsCashAccount = false,
                    DisplayOrder = 100,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for Murabaha receivable recognition.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                },
                new
                {
                    Id = 11L,
                    RuleCode = "ACR-000011",
                    RuleName = "Partner funding payable",
                    GeneralLedgerAccountId = 2105L,
                    GeneralLedgerAccountCode = "2105",
                    GeneralLedgerAccountName = "Partner funding payable",
                    AccountCategoryCode = FinanceAccountingRuleCatalog.Liability,
                    StatementSectionCode = FinanceAccountingRuleCatalog.CurrentLiability,
                    CashFlowCategoryCode = FinanceAccountingRuleCatalog.FinancingCashFlow,
                    IsCashAccount = false,
                    DisplayOrder = 110,
                    EffectiveFromDate = new DateOnly(2026, 1, 1),
                    EffectiveToDate = (DateOnly?)null,
                    StatusId = WorkflowStatusSeedIds.Approved,
                    IsActive = true,
                    Notes = "Seeded baseline for partner-funding liabilities.",
                    SubmittedAtUtc = SeedSubmittedAtUtc,
                    SubmittedByUserId = 1L,
                    ApprovedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ApprovedByUserId = 2L,
                    ActivatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    ActivatedByUserId = 2L,
                    CreatedAtUtc = SeedCreatedAtUtc,
                    CreatedByUserId = 1L,
                    UpdatedAtUtc = SeedSubmittedAtUtc.AddHours(1),
                    UpdatedByUserId = 2L
                });
        });
    }

    private static void ConfigureCardTokenReferences(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<CardTokenReference>(builder =>
        {
            builder.ToTable("card_token_ref_hdr");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("card_token_ref_id");
            builder.Property(entry => entry.CardTokenReferenceNumber).HasColumnName("card_token_ref_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.PartyId).HasColumnName("party_id");
            builder.Property(entry => entry.PartyTypeCode).HasColumnName("party_type_code").HasMaxLength(20).IsRequired();
            builder.Property(entry => entry.IntegrationProviderCode).HasColumnName("provider_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.UsageCode).HasColumnName("usage_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CardBrandCode).HasColumnName("card_brand_code").HasMaxLength(20).IsRequired();
            builder.Property(entry => entry.MaskedPan).HasColumnName("masked_pan").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.ExpiryMonth).HasColumnName("expiry_month");
            builder.Property(entry => entry.ExpiryYear).HasColumnName("expiry_year");
            builder.Property(entry => entry.TokenReference).HasColumnName("token_reference").HasMaxLength(200).IsRequired();
            builder.Property(entry => entry.ExternalCustomerReference).HasColumnName("ext_customer_ref").HasMaxLength(120);
            builder.Property(entry => entry.IsDefault).HasColumnName("is_default");
            builder.Property(entry => entry.StatusId).HasColumnName("status_id");
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.Notes).HasColumnName("notes").HasMaxLength(1000);
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.SuspendedAtUtc).HasColumnName("suspended_at");
            builder.Property(entry => entry.SuspendedByUserId).HasColumnName("suspended_by");
            builder.Property(entry => entry.SuspensionReasonCode).HasColumnName("suspension_reason_code").HasMaxLength(40);
            builder.Property(entry => entry.SuspensionNotes).HasColumnName("suspension_notes").HasMaxLength(1000);
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigurePaymentChannels(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<PaymentChannelConfiguration>(builder =>
        {
            builder.ToTable("pay_channel_cfg_hdr");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("pay_channel_cfg_id");
            builder.Property(entry => entry.ChannelCode).HasColumnName("channel_code").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.ChannelName).HasColumnName("channel_name").HasMaxLength(200).IsRequired();
            builder.Property(entry => entry.BranchId).HasColumnName("branch_id");
            builder.Property(entry => entry.IntegrationProviderCode).HasColumnName("provider_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.ChannelTypeCode).HasColumnName("channel_type_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.UsageCode).HasColumnName("usage_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(entry => entry.OutboundIntegrationEndpointId).HasColumnName("outbound_int_endpoint_id");
            builder.Property(entry => entry.InboundIntegrationEndpointId).HasColumnName("inbound_int_endpoint_id");
            builder.Property(entry => entry.SupportsCardTokenReferences).HasColumnName("supports_card_token_ref");
            builder.Property(entry => entry.UsesWalletRuleEngine).HasColumnName("uses_wallet_rule_engine");
            builder.Property(entry => entry.RequiresCustomerReference).HasColumnName("requires_customer_ref");
            builder.Property(entry => entry.MinimumAmount).HasColumnName("min_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.MaximumAmount).HasColumnName("max_amt").HasPrecision(18, 2);
            builder.Property(entry => entry.SettlementLeadDays).HasColumnName("settlement_lead_days");
            builder.Property(entry => entry.StatusId).HasColumnName("status_id");
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.Notes).HasColumnName("notes").HasMaxLength(1000);
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureCustomerStatements(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<CustomerStatement>(builder =>
        {
            builder.ToTable("ar_stmt_hdr");
            builder.HasKey(statement => statement.Id);
            builder.Property(statement => statement.Id).HasColumnName("ar_stmt_id");
            builder.Property(statement => statement.StatementNumber).HasColumnName("stmt_no").HasMaxLength(60).IsRequired();
            builder.Property(statement => statement.CustomerId).HasColumnName("customer_id");
            builder.Property(statement => statement.CustomerCode).HasColumnName("customer_code").HasMaxLength(60).IsRequired();
            builder.Property(statement => statement.CustomerName).HasColumnName("customer_name").HasMaxLength(250).IsRequired();
            builder.Property(statement => statement.DateFrom).HasColumnName("date_from");
            builder.Property(statement => statement.DateTo).HasColumnName("date_to");
            builder.Property(statement => statement.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(statement => statement.OpeningBalanceAmount).HasColumnName("opening_bal_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.TotalChargeAmount).HasColumnName("total_charge_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.TotalSettlementAmount).HasColumnName("total_settlement_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.ClosingBalanceAmount).HasColumnName("closing_bal_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.OpenInvoiceAmount).HasColumnName("open_inv_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.OverdueInvoiceAmount).HasColumnName("overdue_inv_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.GeneratedAtUtc).HasColumnName("generated_at");
            builder.Property(statement => statement.GeneratedByUserId).HasColumnName("generated_by");
            builder.Property(statement => statement.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(statement => statement.CreatedByUserId).HasColumnName("created_by");
            builder.Property(statement => statement.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(statement => statement.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(statement => statement.Lines)
                .WithOne()
                .HasForeignKey(line => line.CustomerStatementId);

            builder.HasMany(statement => statement.DeliveryLogs)
                .WithOne()
                .HasForeignKey(log => log.CustomerStatementId);
        });

        modelBuilder.Entity<CustomerStatementLine>(builder =>
        {
            builder.ToTable("ar_stmt_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("ar_stmt_ln_id");
            builder.Property(line => line.CustomerStatementId).HasColumnName("ar_stmt_id");
            builder.Property(line => line.EntryType).HasColumnName("entry_type").HasMaxLength(30).IsRequired();
            builder.Property(line => line.DocumentType).HasColumnName("doc_type").HasMaxLength(30).IsRequired();
            builder.Property(line => line.DocumentId).HasColumnName("doc_id");
            builder.Property(line => line.DocumentNumber).HasColumnName("doc_no").HasMaxLength(60).IsRequired();
            builder.Property(line => line.BusinessDate).HasColumnName("biz_date");
            builder.Property(line => line.DueDate).HasColumnName("due_date");
            builder.Property(line => line.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(line => line.ChargeAmount).HasColumnName("charge_amt").HasPrecision(18, 2);
            builder.Property(line => line.SettlementAmount).HasColumnName("settlement_amt").HasPrecision(18, 2);
            builder.Property(line => line.RunningBalanceAmount).HasColumnName("running_bal_amt").HasPrecision(18, 2);
            builder.Property(line => line.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(line => line.ReferenceText).HasColumnName("reference_txt").HasMaxLength(250);
        });

        modelBuilder.Entity<CustomerStatementDeliveryLog>(builder =>
        {
            builder.ToTable("ar_stmt_dlv_log");
            builder.HasKey(log => log.Id);
            builder.Property(log => log.Id).HasColumnName("ar_stmt_dlv_log_id");
            builder.Property(log => log.CustomerStatementId).HasColumnName("ar_stmt_id");
            builder.Property(log => log.DeliveredAtUtc).HasColumnName("delivered_at");
            builder.Property(log => log.ChannelCode).HasColumnName("channel_code").HasMaxLength(30).IsRequired();
            builder.Property(log => log.RecipientAddress).HasColumnName("recipient_addr").HasMaxLength(250);
            builder.Property(log => log.DeliveryStatusCode).HasColumnName("delivery_status_code").HasMaxLength(30).IsRequired();
            builder.Property(log => log.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(log => log.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(log => log.CreatedByUserId).HasColumnName("created_by");
            builder.Property(log => log.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(log => log.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureSupplierStatements(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<SupplierStatement>(builder =>
        {
            builder.ToTable("ap_stmt_hdr");
            builder.HasKey(statement => statement.Id);
            builder.Property(statement => statement.Id).HasColumnName("ap_stmt_id");
            builder.Property(statement => statement.StatementNumber).HasColumnName("stmt_no").HasMaxLength(60).IsRequired();
            builder.Property(statement => statement.SupplierId).HasColumnName("supplier_id");
            builder.Property(statement => statement.SupplierCode).HasColumnName("supplier_code").HasMaxLength(60).IsRequired();
            builder.Property(statement => statement.SupplierName).HasColumnName("supplier_name").HasMaxLength(250).IsRequired();
            builder.Property(statement => statement.DateFrom).HasColumnName("date_from");
            builder.Property(statement => statement.DateTo).HasColumnName("date_to");
            builder.Property(statement => statement.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(statement => statement.OpeningBalanceAmount).HasColumnName("opening_bal_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.TotalChargeAmount).HasColumnName("total_charge_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.TotalSettlementAmount).HasColumnName("total_settlement_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.ClosingBalanceAmount).HasColumnName("closing_bal_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.OpenPayableAmount).HasColumnName("open_payable_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.OverduePayableAmount).HasColumnName("overdue_payable_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.GeneratedAtUtc).HasColumnName("generated_at");
            builder.Property(statement => statement.GeneratedByUserId).HasColumnName("generated_by");
            builder.Property(statement => statement.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(statement => statement.CreatedByUserId).HasColumnName("created_by");
            builder.Property(statement => statement.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(statement => statement.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(statement => statement.Lines)
                .WithOne()
                .HasForeignKey(line => line.SupplierStatementId);

            builder.HasMany(statement => statement.DeliveryLogs)
                .WithOne()
                .HasForeignKey(log => log.SupplierStatementId);
        });

        modelBuilder.Entity<SupplierStatementLine>(builder =>
        {
            builder.ToTable("ap_stmt_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("ap_stmt_ln_id");
            builder.Property(line => line.SupplierStatementId).HasColumnName("ap_stmt_id");
            builder.Property(line => line.EntryType).HasColumnName("entry_type").HasMaxLength(30).IsRequired();
            builder.Property(line => line.DocumentType).HasColumnName("doc_type").HasMaxLength(30).IsRequired();
            builder.Property(line => line.DocumentId).HasColumnName("doc_id");
            builder.Property(line => line.DocumentNumber).HasColumnName("doc_no").HasMaxLength(60).IsRequired();
            builder.Property(line => line.BusinessDate).HasColumnName("biz_date");
            builder.Property(line => line.DueDate).HasColumnName("due_date");
            builder.Property(line => line.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(line => line.ChargeAmount).HasColumnName("charge_amt").HasPrecision(18, 2);
            builder.Property(line => line.SettlementAmount).HasColumnName("settlement_amt").HasPrecision(18, 2);
            builder.Property(line => line.RunningBalanceAmount).HasColumnName("running_bal_amt").HasPrecision(18, 2);
            builder.Property(line => line.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(line => line.ReferenceText).HasColumnName("reference_txt").HasMaxLength(250);
        });

        modelBuilder.Entity<SupplierStatementDeliveryLog>(builder =>
        {
            builder.ToTable("ap_stmt_dlv_log");
            builder.HasKey(log => log.Id);
            builder.Property(log => log.Id).HasColumnName("ap_stmt_dlv_log_id");
            builder.Property(log => log.SupplierStatementId).HasColumnName("ap_stmt_id");
            builder.Property(log => log.DeliveredAtUtc).HasColumnName("delivered_at");
            builder.Property(log => log.ChannelCode).HasColumnName("channel_code").HasMaxLength(30).IsRequired();
            builder.Property(log => log.RecipientAddress).HasColumnName("recipient_addr").HasMaxLength(250);
            builder.Property(log => log.DeliveryStatusCode).HasColumnName("delivery_status_code").HasMaxLength(30).IsRequired();
            builder.Property(log => log.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(log => log.AcknowledgmentStatusCode).HasColumnName("ack_status_code").HasMaxLength(30);
            builder.Property(log => log.AcknowledgedAtUtc).HasColumnName("acknowledged_at");
            builder.Property(log => log.AcknowledgedByUserId).HasColumnName("acknowledged_by");
            builder.Property(log => log.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(log => log.CreatedByUserId).HasColumnName("created_by");
            builder.Property(log => log.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(log => log.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<ReportingSnapshot>(builder =>
        {
            builder.ToTable("rpt_snapshot_hdr");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("rpt_snapshot_id");
            builder.Property(entry => entry.SnapshotNumber).HasColumnName("snapshot_no").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.ReportCode).HasColumnName("report_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.ReportTitle).HasColumnName("report_title").HasMaxLength(120).IsRequired();
            builder.Property(entry => entry.DateFrom).HasColumnName("date_from");
            builder.Property(entry => entry.DateTo).HasColumnName("date_to");
            builder.Property(entry => entry.AsOfDate).HasColumnName("as_of_date");
            builder.Property(entry => entry.RowCount).HasColumnName("row_count");
            builder.Property(entry => entry.JsonPayloadText).HasColumnName("json_payload").IsRequired();
            builder.Property(entry => entry.CsvPayloadText).HasColumnName("csv_payload");
            builder.Property(entry => entry.Notes).HasColumnName("notes").HasMaxLength(4000);
            builder.Property(entry => entry.GeneratedAtUtc).HasColumnName("generated_at").IsRequired();
            builder.Property(entry => entry.GeneratedByUserId).HasColumnName("generated_by").IsRequired();
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureEtaCompliance(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<EtaSubmissionLog>(builder =>
        {
            builder.ToTable("eta_subm_log");
            builder.HasKey(log => log.Id);
            builder.Property(log => log.Id).HasColumnName("eta_subm_id");
            builder.Property(log => log.AccountsReceivableInvoiceId).HasColumnName("ar_inv_id");
            builder.Property(log => log.SubmissionReference).HasColumnName("submit_ref").HasMaxLength(120);
            builder.Property(log => log.EtaUuid).HasColumnName("eta_uuid").HasMaxLength(120);
            builder.Property(log => log.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(log => log.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(log => log.ResponseAtUtc).HasColumnName("response_at");
            builder.Property(log => log.ErrorCode).HasColumnName("err_code").HasMaxLength(60);
            builder.Property(log => log.ErrorMessage).HasColumnName("err_msg").HasMaxLength(1000);
            builder.Property(log => log.PayloadText).HasColumnName("payload_txt");
            builder.Property(log => log.ResponseText).HasColumnName("response_txt");
            builder.Property(log => log.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(log => log.CreatedByUserId).HasColumnName("created_by");
            builder.Property(log => log.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(log => log.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<EtaTransmissionAttempt>(builder =>
        {
            builder.ToTable("eta_tx_attempt");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("eta_tx_attempt_id");
            builder.Property(entry => entry.AccountsReceivableInvoiceId).HasColumnName("ar_inv_id");
            builder.Property(entry => entry.EtaSubmissionLogId).HasColumnName("eta_subm_id");
            builder.Property(entry => entry.IntegrationEndpointId).HasColumnName("int_endpoint_reg_id");
            builder.Property(entry => entry.TransmissionNumber).HasColumnName("tx_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.PayloadText).HasColumnName("payload_txt").IsRequired();
            builder.Property(entry => entry.SignedPayloadText).HasColumnName("signed_payload_txt");
            builder.Property(entry => entry.SignatureText).HasColumnName("signature_txt");
            builder.Property(entry => entry.AdapterReference).HasColumnName("adapter_ref").HasMaxLength(120);
            builder.Property(entry => entry.ResponseText).HasColumnName("response_txt");
            builder.Property(entry => entry.AttemptNumber).HasColumnName("attempt_no");
            builder.Property(entry => entry.AvailableAtUtc).HasColumnName("available_at");
            builder.Property(entry => entry.DispatchedAtUtc).HasColumnName("dispatched_at");
            builder.Property(entry => entry.DispatchedByProcess).HasColumnName("dispatched_by_process").HasMaxLength(60);
            builder.Property(entry => entry.PolledAtUtc).HasColumnName("polled_at");
            builder.Property(entry => entry.PolledByProcess).HasColumnName("polled_by_process").HasMaxLength(60);
            builder.Property(entry => entry.LastErrorText).HasColumnName("last_error_txt").HasMaxLength(1000);
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<EtaDocumentEvent>(builder =>
        {
            builder.ToTable("eta_doc_evt");
            builder.HasKey(evt => evt.Id);
            builder.Property(evt => evt.Id).HasColumnName("eta_doc_evt_id");
            builder.Property(evt => evt.AccountsReceivableInvoiceId).HasColumnName("ar_inv_id");
            builder.Property(evt => evt.EtaSubmissionLogId).HasColumnName("eta_subm_id");
            builder.Property(evt => evt.EventType).HasColumnName("evt_type").HasMaxLength(30).IsRequired();
            builder.Property(evt => evt.EventStatus).HasColumnName("evt_status").HasMaxLength(30).IsRequired();
            builder.Property(evt => evt.EventTimestampUtc).HasColumnName("evt_ts");
            builder.Property(evt => evt.ActorUserId).HasColumnName("actor_user_id");
            builder.Property(evt => evt.PayloadText).HasColumnName("payload_txt");
            builder.Property(evt => evt.ResponseText).HasColumnName("response_txt");
            builder.Property(evt => evt.NotesText).HasColumnName("notes_txt").HasMaxLength(1000);
        });
    }

    private static void ConfigureInventoryAndFinanceTraceability(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<InventoryMovement>(builder =>
        {
            builder.ToTable("inv_move");
            builder.HasKey(movement => movement.Id);
            builder.Property(movement => movement.Id).HasColumnName("inv_move_id");
            builder.Property(movement => movement.MovementNumber).HasColumnName("move_no").HasMaxLength(60).IsRequired();
            builder.Property(movement => movement.MovementType).HasColumnName("move_type").HasMaxLength(30).IsRequired();
            builder.Property(movement => movement.BranchId).HasColumnName("branch_id");
            builder.Property(movement => movement.ItemId).HasColumnName("item_id");
            builder.Property(movement => movement.FromWarehouseId).HasColumnName("from_wh_id");
            builder.Property(movement => movement.FromWarehouseLocationId).HasColumnName("from_wh_loc_id");
            builder.Property(movement => movement.ToWarehouseId).HasColumnName("to_wh_id");
            builder.Property(movement => movement.ToWarehouseLocationId).HasColumnName("to_wh_loc_id");
            builder.Property(movement => movement.BatchNumber).HasColumnName("batch_no").HasMaxLength(60);
            builder.Property(movement => movement.SerialNumber).HasColumnName("serial_no").HasMaxLength(100);
            builder.Property(movement => movement.StockStatus).HasColumnName("stock_status").HasMaxLength(30).IsRequired();
            builder.Property(movement => movement.QuantityMoved).HasColumnName("qty_moved").HasPrecision(18, 4);
            builder.Property(movement => movement.UnitCost).HasColumnName("unit_cost").HasPrecision(18, 2);
            builder.Property(movement => movement.MovedAtUtc).HasColumnName("moved_at");
            builder.Property(movement => movement.StatusId).HasColumnName("status_id");
            builder.Property(movement => movement.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(movement => movement.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(movement => movement.UpdatedAtUtc);
            builder.Ignore(movement => movement.UpdatedByUserId);

            builder.HasData(new
            {
                Id = 1L,
                MovementNumber = "IM-000001",
                MovementType = "GRN_RECEIPT",
                BranchId = 1L,
                ItemId = 1001L,
                FromWarehouseId = (long?)null,
                FromWarehouseLocationId = (long?)null,
                ToWarehouseId = 1L,
                ToWarehouseLocationId = (long?)null,
                BatchNumber = "BATCH-1001-A",
                SerialNumber = (string?)null,
                StockStatus = "AVAILABLE",
                QuantityMoved = 50m,
                UnitCost = 24m,
                MovedAtUtc = SeedSubmittedAtUtc.AddDays(1),
                StatusId = WorkflowStatusSeedIds.Posted,
                CreatedAtUtc = SeedSubmittedAtUtc.AddDays(1),
                CreatedByUserId = 1L
            });
        });

        modelBuilder.Entity<InventoryStatusControl>(builder =>
        {
            builder.ToTable("inv_status_ctrl_hdr");
            builder.HasKey(control => control.Id);
            builder.Property(control => control.Id).HasColumnName("inv_status_ctrl_id");
            builder.Property(control => control.ControlNumber).HasColumnName("ctrl_no").HasMaxLength(60).IsRequired();
            builder.Property(control => control.BranchId).HasColumnName("branch_id");
            builder.Property(control => control.WarehouseId).HasColumnName("wh_id");
            builder.Property(control => control.ControlDate).HasColumnName("ctrl_dt");
            builder.Property(control => control.ReasonCode).HasColumnName("reason_code").HasMaxLength(40).IsRequired();
            builder.Property(control => control.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(control => control.StatusId).HasColumnName("status_id");
            builder.Property(control => control.TotalQuantityAffected).HasColumnName("total_qty_affected").HasPrecision(18, 4);
            builder.Property(control => control.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(control => control.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(control => control.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(control => control.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(control => control.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(control => control.PostedByUserId).HasColumnName("posted_by");
            builder.Property(control => control.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(control => control.CreatedByUserId).HasColumnName("created_by");
            builder.Property(control => control.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(control => control.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(control => control.Lines)
                .WithOne()
                .HasForeignKey(line => line.InventoryStatusControlId);
        });

        modelBuilder.Entity<InventoryStatusControlLine>(builder =>
        {
            builder.ToTable("inv_status_ctrl_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("inv_status_ctrl_ln_id");
            builder.Property(line => line.InventoryStatusControlId).HasColumnName("inv_status_ctrl_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.WarehouseLocationId).HasColumnName("wh_loc_id");
            builder.Property(line => line.QuantityAffected).HasColumnName("qty_affected").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.UnitCost).HasColumnName("unit_cost").HasPrecision(18, 2);
            builder.Property(line => line.CurrentStockStatus).HasColumnName("current_stock_status").HasMaxLength(30).IsRequired();
            builder.Property(line => line.TargetStockStatus).HasColumnName("target_stock_status").HasMaxLength(30).IsRequired();
            builder.Property(line => line.BatchNumber).HasColumnName("batch_no").HasMaxLength(60);
            builder.Property(line => line.SerialNumber).HasColumnName("serial_no").HasMaxLength(100);
            builder.Property(line => line.ExpiryDate).HasColumnName("expiry_dt");
            builder.Property(line => line.Notes).HasColumnName("notes_txt").HasMaxLength(500);
            builder.Property(line => line.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(line => line.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(line => line.UpdatedAtUtc);
            builder.Ignore(line => line.UpdatedByUserId);
        });

        modelBuilder.Entity<StockCount>(builder =>
        {
            builder.ToTable("inv_cnt_hdr");
            builder.HasKey(stockCount => stockCount.Id);
            builder.Property(stockCount => stockCount.Id).HasColumnName("inv_cnt_id");
            builder.Property(stockCount => stockCount.CountNumber).HasColumnName("cnt_no").HasMaxLength(60).IsRequired();
            builder.Property(stockCount => stockCount.BranchId).HasColumnName("branch_id");
            builder.Property(stockCount => stockCount.WarehouseId).HasColumnName("wh_id");
            builder.Property(stockCount => stockCount.CountDate).HasColumnName("cnt_dt");
            builder.Property(stockCount => stockCount.CountTypeCode).HasColumnName("cnt_type_code").HasMaxLength(30).IsRequired();
            builder.Property(stockCount => stockCount.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(stockCount => stockCount.StatusId).HasColumnName("status_id");
            builder.Property(stockCount => stockCount.TotalVarianceAmount).HasColumnName("total_var_amt").HasPrecision(18, 2);
            builder.Property(stockCount => stockCount.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(stockCount => stockCount.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(stockCount => stockCount.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(stockCount => stockCount.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(stockCount => stockCount.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(stockCount => stockCount.PostedByUserId).HasColumnName("posted_by");
            builder.Property(stockCount => stockCount.InventoryAdjustmentId).HasColumnName("inv_adj_id");
            builder.Property(stockCount => stockCount.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(stockCount => stockCount.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(stockCount => stockCount.CreatedByUserId).HasColumnName("created_by");
            builder.Property(stockCount => stockCount.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(stockCount => stockCount.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(stockCount => stockCount.Lines)
                .WithOne()
                .HasForeignKey(line => line.StockCountId);
        });

        modelBuilder.Entity<StockCountLine>(builder =>
        {
            builder.ToTable("inv_cnt_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("inv_cnt_ln_id");
            builder.Property(line => line.StockCountId).HasColumnName("inv_cnt_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.WarehouseLocationId).HasColumnName("wh_loc_id");
            builder.Property(line => line.BookQuantity).HasColumnName("book_qty").HasPrecision(18, 4);
            builder.Property(line => line.CountedQuantity).HasColumnName("counted_qty").HasPrecision(18, 4);
            builder.Property(line => line.VarianceQuantity).HasColumnName("variance_qty").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.UnitCost).HasColumnName("unit_cost").HasPrecision(18, 2);
            builder.Property(line => line.VarianceAmount).HasColumnName("variance_amt").HasPrecision(18, 2);
            builder.Property(line => line.StockStatus).HasColumnName("stock_status").HasMaxLength(30).IsRequired();
            builder.Property(line => line.BatchNumber).HasColumnName("batch_no").HasMaxLength(60);
            builder.Property(line => line.SerialNumber).HasColumnName("serial_no").HasMaxLength(100);
            builder.Property(line => line.Notes).HasColumnName("notes_txt").HasMaxLength(500);
            builder.Property(line => line.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(line => line.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(line => line.UpdatedAtUtc);
            builder.Ignore(line => line.UpdatedByUserId);
        });

        modelBuilder.Entity<WarehouseTransfer>(builder =>
        {
            builder.ToTable("inv_trf_hdr");
            builder.HasKey(transfer => transfer.Id);
            builder.Property(transfer => transfer.Id).HasColumnName("inv_trf_id");
            builder.Property(transfer => transfer.TransferNumber).HasColumnName("trf_no").HasMaxLength(60).IsRequired();
            builder.Property(transfer => transfer.BranchId).HasColumnName("branch_id");
            builder.Property(transfer => transfer.FromWarehouseId).HasColumnName("from_wh_id");
            builder.Property(transfer => transfer.ToWarehouseId).HasColumnName("to_wh_id");
            builder.Property(transfer => transfer.TransferDate).HasColumnName("trf_dt");
            builder.Property(transfer => transfer.ReasonCode).HasColumnName("reason_code").HasMaxLength(40).IsRequired();
            builder.Property(transfer => transfer.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(transfer => transfer.StatusId).HasColumnName("status_id");
            builder.Property(transfer => transfer.TotalTransferQuantity).HasColumnName("total_trf_qty").HasPrecision(18, 4);
            builder.Property(transfer => transfer.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(transfer => transfer.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(transfer => transfer.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(transfer => transfer.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(transfer => transfer.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(transfer => transfer.PostedByUserId).HasColumnName("posted_by");
            builder.Property(transfer => transfer.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(transfer => transfer.CreatedByUserId).HasColumnName("created_by");
            builder.Property(transfer => transfer.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(transfer => transfer.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(transfer => transfer.Lines)
                .WithOne()
                .HasForeignKey(line => line.WarehouseTransferId);
        });

        modelBuilder.Entity<WarehouseTransferLine>(builder =>
        {
            builder.ToTable("inv_trf_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("inv_trf_ln_id");
            builder.Property(line => line.WarehouseTransferId).HasColumnName("inv_trf_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.FromWarehouseLocationId).HasColumnName("from_wh_loc_id");
            builder.Property(line => line.ToWarehouseLocationId).HasColumnName("to_wh_loc_id");
            builder.Property(line => line.QuantityTransferred).HasColumnName("qty_trf").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.UnitCost).HasColumnName("unit_cost").HasPrecision(18, 2);
            builder.Property(line => line.StockStatus).HasColumnName("stock_status").HasMaxLength(30).IsRequired();
            builder.Property(line => line.BatchNumber).HasColumnName("batch_no").HasMaxLength(60);
            builder.Property(line => line.SerialNumber).HasColumnName("serial_no").HasMaxLength(100);
            builder.Property(line => line.Notes).HasColumnName("notes_txt").HasMaxLength(500);
            builder.Property(line => line.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(line => line.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(line => line.UpdatedAtUtc);
            builder.Ignore(line => line.UpdatedByUserId);
        });

        modelBuilder.Entity<ReplenishmentRule>(builder =>
        {
            builder.ToTable("inv_replen_rule");
            builder.HasKey(rule => rule.Id);
            builder.Property(rule => rule.Id).HasColumnName("inv_replen_rule_id");
            builder.Property(rule => rule.RuleCode).HasColumnName("rule_code").HasMaxLength(60).IsRequired();
            builder.Property(rule => rule.RuleName).HasColumnName("rule_name").HasMaxLength(200).IsRequired();
            builder.Property(rule => rule.BranchId).HasColumnName("branch_id");
            builder.Property(rule => rule.TargetWarehouseId).HasColumnName("target_wh_id");
            builder.Property(rule => rule.PreferredSourceWarehouseId).HasColumnName("preferred_source_wh_id");
            builder.Property(rule => rule.ItemId).HasColumnName("item_id");
            builder.Property(rule => rule.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(rule => rule.ReorderPointQuantity).HasColumnName("reorder_point_qty").HasPrecision(18, 4);
            builder.Property(rule => rule.TargetSafetyStockQuantity).HasColumnName("target_safety_qty").HasPrecision(18, 4);
            builder.Property(rule => rule.TargetStockQuantity).HasColumnName("target_stock_qty").HasPrecision(18, 4);
            builder.Property(rule => rule.SourceSafetyStockQuantity).HasColumnName("source_safety_qty").HasPrecision(18, 4);
            builder.Property(rule => rule.Priority).HasColumnName("priority_no");
            builder.Property(rule => rule.EffectiveFromDate).HasColumnName("effective_from_dt");
            builder.Property(rule => rule.EffectiveToDate).HasColumnName("effective_to_dt");
            builder.Property(rule => rule.StatusId).HasColumnName("status_id");
            builder.Property(rule => rule.IsActive).HasColumnName("is_active");
            builder.Property(rule => rule.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(rule => rule.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(rule => rule.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(rule => rule.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(rule => rule.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(rule => rule.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(rule => rule.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(rule => rule.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(rule => rule.CreatedByUserId).HasColumnName("created_by");
            builder.Property(rule => rule.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(rule => rule.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<InventoryAdjustment>(builder =>
        {
            builder.ToTable("inv_adj_hdr");
            builder.HasKey(adjustment => adjustment.Id);
            builder.Property(adjustment => adjustment.Id).HasColumnName("inv_adj_id");
            builder.Property(adjustment => adjustment.AdjustmentNumber).HasColumnName("adj_no").HasMaxLength(60).IsRequired();
            builder.Property(adjustment => adjustment.BranchId).HasColumnName("branch_id");
            builder.Property(adjustment => adjustment.WarehouseId).HasColumnName("wh_id");
            builder.Property(adjustment => adjustment.AdjustmentDate).HasColumnName("adj_dt");
            builder.Property(adjustment => adjustment.ReasonCode).HasColumnName("reason_code").HasMaxLength(40).IsRequired();
            builder.Property(adjustment => adjustment.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(adjustment => adjustment.StatusId).HasColumnName("status_id");
            builder.Property(adjustment => adjustment.TotalAdjustmentAmount).HasColumnName("total_adj_amt").HasPrecision(18, 2);
            builder.Property(adjustment => adjustment.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(adjustment => adjustment.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(adjustment => adjustment.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(adjustment => adjustment.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(adjustment => adjustment.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(adjustment => adjustment.PostedByUserId).HasColumnName("posted_by");
            builder.Property(adjustment => adjustment.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(adjustment => adjustment.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(adjustment => adjustment.CreatedByUserId).HasColumnName("created_by");
            builder.Property(adjustment => adjustment.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(adjustment => adjustment.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(adjustment => adjustment.Lines)
                .WithOne()
                .HasForeignKey(line => line.InventoryAdjustmentId);
        });

        modelBuilder.Entity<InventoryAdjustmentLine>(builder =>
        {
            builder.ToTable("inv_adj_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("inv_adj_ln_id");
            builder.Property(line => line.InventoryAdjustmentId).HasColumnName("inv_adj_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.WarehouseLocationId).HasColumnName("wh_loc_id");
            builder.Property(line => line.QuantityDelta).HasColumnName("qty_delta").HasPrecision(18, 4);
            builder.Property(line => line.UnitOfMeasureCode).HasColumnName("uom_code").HasMaxLength(20).IsRequired();
            builder.Property(line => line.UnitCost).HasColumnName("unit_cost").HasPrecision(18, 2);
            builder.Property(line => line.LineAmount).HasColumnName("line_amt").HasPrecision(18, 2);
            builder.Property(line => line.StockStatus).HasColumnName("stock_status").HasMaxLength(30).IsRequired();
            builder.Property(line => line.BatchNumber).HasColumnName("batch_no").HasMaxLength(60);
            builder.Property(line => line.SerialNumber).HasColumnName("serial_no").HasMaxLength(100);
            builder.Property(line => line.Notes).HasColumnName("notes_txt").HasMaxLength(500);
            builder.Property(line => line.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(line => line.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(line => line.UpdatedAtUtc);
            builder.Ignore(line => line.UpdatedByUserId);
        });

        modelBuilder.Entity<GeneralLedgerBatch>(builder =>
        {
            builder.ToTable("gl_batch");
            builder.HasKey(batch => batch.Id);
            builder.Property(batch => batch.Id).HasColumnName("gl_batch_id");
            builder.Property(batch => batch.BatchNumber).HasColumnName("batch_no").HasMaxLength(60).IsRequired();
            builder.Property(batch => batch.BatchType).HasColumnName("batch_type").HasMaxLength(30).IsRequired();
            builder.Property(batch => batch.BranchId).HasColumnName("branch_id");
            builder.Property(batch => batch.PeriodId).HasColumnName("period_id");
            builder.Property(batch => batch.StatusId).HasColumnName("status_id");
            builder.Property(batch => batch.DescriptionText).HasColumnName("description_txt").HasMaxLength(500);
            builder.Property(batch => batch.SourceModule).HasColumnName("source_module").HasMaxLength(30);
            builder.Property(batch => batch.SourceDocumentId).HasColumnName("source_doc_id");
            builder.Property(batch => batch.BatchTotalAmount).HasColumnName("batch_total_amt").HasPrecision(18, 2);
            builder.Property(batch => batch.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(batch => batch.CreatedByUserId).HasColumnName("created_by");
            builder.Property(batch => batch.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(batch => batch.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(batch => batch.Journals)
                .WithOne()
                .HasForeignKey(journal => journal.GeneralLedgerBatchId);

            builder.HasData(new
            {
                Id = 1L,
                BatchNumber = "GLB-000001",
                BatchType = "AP_BILL",
                BranchId = (long?)null,
                PeriodId = 1L,
                StatusId = WorkflowStatusSeedIds.Posted,
                DescriptionText = "AP bill posting for BILL-000001",
                SourceModule = "FINANCE",
                SourceDocumentId = 1L,
                BatchTotalAmount = 2992.5m,
                CreatedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                CreatedByUserId = 2L,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<GeneralLedgerJournal>(builder =>
        {
            builder.ToTable("gl_jrnl");
            builder.HasKey(journal => journal.Id);
            builder.Property(journal => journal.Id).HasColumnName("gl_jrnl_id");
            builder.Property(journal => journal.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(journal => journal.JournalNumber).HasColumnName("jrnl_no").HasMaxLength(60).IsRequired();
            builder.Property(journal => journal.JournalType).HasColumnName("jrnl_type").HasMaxLength(30).IsRequired();
            builder.Property(journal => journal.PostingDate).HasColumnName("posting_date");
            builder.Property(journal => journal.TaxDate).HasColumnName("tax_date");
            builder.Property(journal => journal.DocumentDate).HasColumnName("doc_date");
            builder.Property(journal => journal.StatusId).HasColumnName("status_id");
            builder.Property(journal => journal.DescriptionText).HasColumnName("description_txt").HasMaxLength(500);
            builder.Property(journal => journal.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(journal => journal.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(journal => journal.TotalAmount);

            builder.HasMany(journal => journal.Lines)
                .WithOne()
                .HasForeignKey(line => line.GeneralLedgerJournalId);

            builder.HasData(new
            {
                Id = 1L,
                GeneralLedgerBatchId = 1L,
                JournalNumber = "JRNL-000001",
                JournalType = "AP_BILL",
                PostingDate = new DateOnly(2026, 4, 5),
                TaxDate = new DateOnly(2026, 4, 5),
                DocumentDate = new DateOnly(2026, 4, 5),
                StatusId = WorkflowStatusSeedIds.Posted,
                DescriptionText = "Supplier bill BILL-000001",
                CreatedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                CreatedByUserId = 2L
            });
        });

        modelBuilder.Entity<GeneralLedgerJournalLine>(builder =>
        {
            builder.ToTable("gl_jrnl_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("gl_jrnl_ln_id");
            builder.Property(line => line.GeneralLedgerJournalId).HasColumnName("gl_jrnl_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.GeneralLedgerAccountId).HasColumnName("gl_acct_id");
            builder.Property(line => line.BranchId).HasColumnName("branch_id");
            builder.Property(line => line.DepartmentId).HasColumnName("dept_id");
            builder.Property(line => line.PartyId).HasColumnName("party_id");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.DebitAmount).HasColumnName("dr_amt").HasPrecision(18, 2);
            builder.Property(line => line.CreditAmount).HasColumnName("cr_amt").HasPrecision(18, 2);
            builder.Property(line => line.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10);
            builder.Property(line => line.FxRate).HasColumnName("fx_rate").HasPrecision(18, 6);
            builder.Property(line => line.LineDescription).HasColumnName("line_desc").HasMaxLength(500);
            builder.Property(line => line.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(line => line.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(line => line.UpdatedAtUtc);
            builder.Ignore(line => line.UpdatedByUserId);

            builder.HasData(
                new
                {
                    Id = 1L,
                    GeneralLedgerJournalId = 1L,
                    LineNumber = 1,
                    GeneralLedgerAccountId = 2001L,
                    BranchId = (long?)null,
                    DepartmentId = (long?)null,
                    PartyId = 1L,
                    ItemId = (long?)null,
                    DebitAmount = 0m,
                    CreditAmount = 2992.5m,
                    CurrencyCode = "EGP",
                    FxRate = 1m,
                    LineDescription = "Accounts payable recognition",
                    CreatedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                    CreatedByUserId = 2L
                },
                new
                {
                    Id = 2L,
                    GeneralLedgerJournalId = 1L,
                    LineNumber = 2,
                    GeneralLedgerAccountId = 1401L,
                    BranchId = (long?)null,
                    DepartmentId = (long?)null,
                    PartyId = 1L,
                    ItemId = (long?)null,
                    DebitAmount = 2992.5m,
                    CreditAmount = 0m,
                    CurrencyCode = "EGP",
                    FxRate = 1m,
                    LineDescription = "Inventory / expense interim recognition",
                    CreatedAtUtc = SeedSubmittedAtUtc.AddDays(2),
                    CreatedByUserId = 2L
                });
        });
    }

    private static void ConfigureReconciliationAndClose(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<FinanceCloseJournal>(builder =>
        {
            builder.ToTable("fin_close_jrnl_hdr");
            builder.HasKey(journal => journal.Id);
            builder.Property(journal => journal.Id).HasColumnName("fin_close_jrnl_id");
            builder.Property(journal => journal.CloseJournalNumber).HasColumnName("close_jrnl_no").HasMaxLength(60).IsRequired();
            builder.Property(journal => journal.AccountingPeriodId).HasColumnName("period_id");
            builder.Property(journal => journal.BranchId).HasColumnName("branch_id");
            builder.Property(journal => journal.JournalClassCode).HasColumnName("jrnl_class_code").HasMaxLength(30).IsRequired();
            builder.Property(journal => journal.PostingDate).HasColumnName("posting_date");
            builder.Property(journal => journal.DocumentDate).HasColumnName("doc_date");
            builder.Property(journal => journal.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(journal => journal.StatusId).HasColumnName("status_id");
            builder.Property(journal => journal.TotalDebitAmount).HasColumnName("total_debit_amt").HasPrecision(18, 2);
            builder.Property(journal => journal.TotalCreditAmount).HasColumnName("total_credit_amt").HasPrecision(18, 2);
            builder.Property(journal => journal.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(journal => journal.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(journal => journal.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(journal => journal.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(journal => journal.PostedAtUtc).HasColumnName("posted_at");
            builder.Property(journal => journal.PostedByUserId).HasColumnName("posted_by");
            builder.Property(journal => journal.GeneralLedgerBatchId).HasColumnName("gl_batch_id");
            builder.Property(journal => journal.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(journal => journal.CreatedByUserId).HasColumnName("created_by");
            builder.Property(journal => journal.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(journal => journal.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(journal => journal.Lines)
                .WithOne()
                .HasForeignKey(line => line.FinanceCloseJournalId);
        });

        modelBuilder.Entity<FinanceCloseJournalLine>(builder =>
        {
            builder.ToTable("fin_close_jrnl_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("fin_close_jrnl_ln_id");
            builder.Property(line => line.FinanceCloseJournalId).HasColumnName("fin_close_jrnl_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.GeneralLedgerAccountId).HasColumnName("gl_acct_id");
            builder.Property(line => line.BranchId).HasColumnName("branch_id");
            builder.Property(line => line.DepartmentId).HasColumnName("dept_id");
            builder.Property(line => line.PartyId).HasColumnName("party_id");
            builder.Property(line => line.ItemId).HasColumnName("item_id");
            builder.Property(line => line.DebitAmount).HasColumnName("debit_amt").HasPrecision(18, 2);
            builder.Property(line => line.CreditAmount).HasColumnName("credit_amt").HasPrecision(18, 2);
            builder.Property(line => line.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10);
            builder.Property(line => line.FxRate).HasColumnName("fx_rate").HasPrecision(18, 8);
            builder.Property(line => line.LineDescription).HasColumnName("line_desc").HasMaxLength(500);
            builder.Property(line => line.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(line => line.CreatedByUserId).HasColumnName("created_by");
            builder.Ignore(line => line.UpdatedAtUtc);
            builder.Ignore(line => line.UpdatedByUserId);
        });

        modelBuilder.Entity<AccountingPeriod>(builder =>
        {
            builder.ToTable("gl_period");
            builder.HasKey(period => period.Id);
            builder.Property(period => period.Id).HasColumnName("period_id");
            builder.Property(period => period.PeriodCode).HasColumnName("period_code").HasMaxLength(30).IsRequired();
            builder.Property(period => period.StartDate).HasColumnName("start_date");
            builder.Property(period => period.EndDate).HasColumnName("end_date");
            builder.Property(period => period.CloseStatusCode).HasColumnName("close_status_code").HasMaxLength(30).IsRequired();
            builder.Property(period => period.IsYearEnd).HasColumnName("is_year_end");
            builder.Property(period => period.ReadyForCloseAtUtc).HasColumnName("ready_for_close_at");
            builder.Property(period => period.ReadyForCloseByUserId).HasColumnName("ready_for_close_by");
            builder.Property(period => period.ClosedAtUtc).HasColumnName("closed_at");
            builder.Property(period => period.ClosedByUserId).HasColumnName("closed_by");
            builder.Property(period => period.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(period => period.CreatedByUserId).HasColumnName("created_by");
            builder.Property(period => period.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(period => period.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasData(new
            {
                Id = 1L,
                PeriodCode = "2026-04",
                StartDate = new DateOnly(2026, 4, 1),
                EndDate = new DateOnly(2026, 4, 30),
                CloseStatusCode = "OPEN",
                IsYearEnd = false,
                ReadyForCloseAtUtc = (DateTime?)null,
                ReadyForCloseByUserId = (long?)null,
                ClosedAtUtc = (DateTime?)null,
                ClosedByUserId = (long?)null,
                CreatedAtUtc = SeedCreatedAtUtc,
                CreatedByUserId = (long?)null,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            },
            new
            {
                Id = 2L,
                PeriodCode = "2026-05",
                StartDate = new DateOnly(2026, 5, 1),
                EndDate = new DateOnly(2026, 5, 31),
                CloseStatusCode = "OPEN",
                IsYearEnd = false,
                ReadyForCloseAtUtc = (DateTime?)null,
                ReadyForCloseByUserId = (long?)null,
                ClosedAtUtc = (DateTime?)null,
                ClosedByUserId = (long?)null,
                CreatedAtUtc = SeedCreatedAtUtc,
                CreatedByUserId = (long?)null,
                UpdatedAtUtc = (DateTime?)null,
                UpdatedByUserId = (long?)null
            });
        });

        modelBuilder.Entity<BankStatement>(builder =>
        {
            builder.ToTable("bank_stmt_hdr");
            builder.HasKey(statement => statement.Id);
            builder.Property(statement => statement.Id).HasColumnName("bank_stmt_id");
            builder.Property(statement => statement.StatementNumber).HasColumnName("stmt_no").HasMaxLength(60).IsRequired();
            builder.Property(statement => statement.BankAccountCode).HasColumnName("bank_acct_code").HasMaxLength(60).IsRequired();
            builder.Property(statement => statement.StatementDate).HasColumnName("stmt_date");
            builder.Property(statement => statement.CurrencyCode).HasColumnName("currency_code").HasMaxLength(10).IsRequired();
            builder.Property(statement => statement.OpeningBalanceAmount).HasColumnName("opening_bal_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.ClosingBalanceAmount).HasColumnName("closing_bal_amt").HasPrecision(18, 2);
            builder.Property(statement => statement.ImportStatusCode).HasColumnName("import_status_code").HasMaxLength(30).IsRequired();
            builder.Property(statement => statement.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(statement => statement.CreatedByUserId).HasColumnName("created_by");
            builder.Property(statement => statement.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(statement => statement.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(statement => statement.Lines)
                .WithOne()
                .HasForeignKey(line => line.BankStatementId);
        });

        modelBuilder.Entity<BankStatementLine>(builder =>
        {
            builder.ToTable("bank_stmt_ln");
            builder.HasKey(line => line.Id);
            builder.Property(line => line.Id).HasColumnName("bank_stmt_ln_id");
            builder.Property(line => line.BankStatementId).HasColumnName("bank_stmt_id");
            builder.Property(line => line.LineNumber).HasColumnName("line_no");
            builder.Property(line => line.TransactionDate).HasColumnName("txn_date");
            builder.Property(line => line.ExternalReference).HasColumnName("ext_ref").HasMaxLength(120);
            builder.Property(line => line.DescriptionText).HasColumnName("description_txt").HasMaxLength(500);
            builder.Property(line => line.DebitAmount).HasColumnName("debit_amt").HasPrecision(18, 2);
            builder.Property(line => line.CreditAmount).HasColumnName("credit_amt").HasPrecision(18, 2);
            builder.Property(line => line.RunningBalanceAmount).HasColumnName("running_bal_amt").HasPrecision(18, 2);
            builder.Property(line => line.IsReconciled).HasColumnName("is_reconciled");
            builder.Property(line => line.AccountsReceivableReceiptId).HasColumnName("ar_rcpt_id");
            builder.Property(line => line.AccountsPayablePaymentId).HasColumnName("ap_pay_id");
            builder.Property(line => line.CustomerRefundId).HasColumnName("ar_refund_id");
            builder.Property(line => line.ReconciledAtUtc).HasColumnName("reconciled_at");
            builder.Property(line => line.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(line => line.CreatedByUserId).HasColumnName("created_by");
            builder.Property(line => line.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(line => line.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<ReceiptReconciliationRun>(builder =>
        {
            builder.ToTable("fin_recon_hdr");
            builder.HasKey(run => run.Id);
            builder.Property(run => run.Id).HasColumnName("fin_recon_id");
            builder.Property(run => run.RunNumber).HasColumnName("recon_no").HasMaxLength(60).IsRequired();
            builder.Property(run => run.AccountingPeriodId).HasColumnName("period_id");
            builder.Property(run => run.BankStatementId).HasColumnName("bank_stmt_id");
            builder.Property(run => run.RunStatusCode).HasColumnName("run_status_code").HasMaxLength(30).IsRequired();
            builder.Property(run => run.MatchedItemCount).HasColumnName("matched_item_count");
            builder.Property(run => run.UnmatchedItemCount).HasColumnName("unmatched_item_count");
            builder.Property(run => run.StartedAtUtc).HasColumnName("started_at");
            builder.Property(run => run.CompletedAtUtc).HasColumnName("completed_at");
            builder.Property(run => run.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(run => run.CreatedByUserId).HasColumnName("created_by");
            builder.Property(run => run.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(run => run.UpdatedByUserId).HasColumnName("updated_by");

            builder.HasMany(run => run.Items)
                .WithOne()
                .HasForeignKey(item => item.ReceiptReconciliationRunId);
        });

        modelBuilder.Entity<ReceiptReconciliationItem>(builder =>
        {
            builder.ToTable("fin_recon_ln");
            builder.HasKey(item => item.Id);
            builder.Property(item => item.Id).HasColumnName("fin_recon_ln_id");
            builder.Property(item => item.ReceiptReconciliationRunId).HasColumnName("fin_recon_id");
            builder.Property(item => item.BankStatementLineId).HasColumnName("bank_stmt_ln_id");
            builder.Property(item => item.AccountsReceivableReceiptId).HasColumnName("ar_rcpt_id");
            builder.Property(item => item.AccountsPayablePaymentId).HasColumnName("ap_pay_id");
            builder.Property(item => item.CustomerRefundId).HasColumnName("ar_refund_id");
            builder.Property(item => item.MatchedDocumentType).HasColumnName("matched_doc_type").HasMaxLength(30).IsRequired();
            builder.Property(item => item.MatchStatusCode).HasColumnName("match_status_code").HasMaxLength(30).IsRequired();
            builder.Property(item => item.StatementAmount).HasColumnName("stmt_amt").HasPrecision(18, 2);
            builder.Property(item => item.MatchedDocumentAmount).HasColumnName("matched_doc_amt").HasPrecision(18, 2);
            builder.Property(item => item.DifferenceAmount).HasColumnName("difference_amt").HasPrecision(18, 2);
            builder.Property(item => item.Notes).HasColumnName("notes_txt").HasMaxLength(500);
            builder.Property(item => item.ResolutionCode).HasColumnName("resolution_code").HasMaxLength(30);
            builder.Property(item => item.OverrideApprovalRoleCode).HasColumnName("override_approval_role_code").HasMaxLength(40);
            builder.Property(item => item.OverrideReasonCode).HasColumnName("override_reason_code").HasMaxLength(40);
            builder.Property(item => item.ResolvedAtUtc).HasColumnName("resolved_at");
            builder.Property(item => item.ResolvedByUserId).HasColumnName("resolved_by");
            builder.Property(item => item.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(item => item.CreatedByUserId).HasColumnName("created_by");
            builder.Property(item => item.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(item => item.UpdatedByUserId).HasColumnName("updated_by");
        });
    }

    private static void ConfigureIntegrationRegistry(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<IntegrationEndpointRegistryEntry>(builder =>
        {
            builder.ToTable("int_endpoint_reg");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("int_endpoint_reg_id");
            builder.Property(entry => entry.EndpointCode).HasColumnName("endpoint_code").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.EndpointName).HasColumnName("endpoint_name").HasMaxLength(200).IsRequired();
            builder.Property(entry => entry.IntegrationProviderCode).HasColumnName("provider_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.EnvironmentCode).HasColumnName("environment_code").HasMaxLength(20).IsRequired();
            builder.Property(entry => entry.DirectionCode).HasColumnName("direction_code").HasMaxLength(20).IsRequired();
            builder.Property(entry => entry.TransportCode).HasColumnName("transport_code").HasMaxLength(20).IsRequired();
            builder.Property(entry => entry.HttpMethodCode).HasColumnName("http_method_code").HasMaxLength(20).IsRequired();
            builder.Property(entry => entry.BaseUrl).HasColumnName("base_url").HasMaxLength(500).IsRequired();
            builder.Property(entry => entry.RelativePath).HasColumnName("relative_path").HasMaxLength(500);
            builder.Property(entry => entry.AuthenticationModeCode).HasColumnName("auth_mode_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.CredentialReference).HasColumnName("credential_ref").HasMaxLength(200);
            builder.Property(entry => entry.TimeoutSeconds).HasColumnName("timeout_sec");
            builder.Property(entry => entry.RetryPolicyCode).HasColumnName("retry_policy_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.MaxRetryCount).HasColumnName("max_retry_count");
            builder.Property(entry => entry.IsIdempotencyKeyRequired).HasColumnName("requires_idempotency_key");
            builder.Property(entry => entry.StatusId).HasColumnName("status_id");
            builder.Property(entry => entry.IsActive).HasColumnName("is_active");
            builder.Property(entry => entry.Notes).HasColumnName("notes_txt").HasMaxLength(1000);
            builder.Property(entry => entry.SubmittedAtUtc).HasColumnName("submitted_at");
            builder.Property(entry => entry.SubmittedByUserId).HasColumnName("submitted_by");
            builder.Property(entry => entry.ApprovedAtUtc).HasColumnName("approved_at");
            builder.Property(entry => entry.ApprovedByUserId).HasColumnName("approved_by");
            builder.Property(entry => entry.ActivatedAtUtc).HasColumnName("activated_at");
            builder.Property(entry => entry.ActivatedByUserId).HasColumnName("activated_by");
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<OutboxEvent>(builder =>
        {
            builder.ToTable("int_outbox_evt");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("int_outbox_evt_id");
            builder.Property(entry => entry.EventNumber).HasColumnName("event_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.SourceModuleCode).HasColumnName("source_module_code").HasMaxLength(40).IsRequired();
            builder.Property(entry => entry.AggregateType).HasColumnName("aggregate_type").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.AggregateId).HasColumnName("aggregate_id");
            builder.Property(entry => entry.EventType).HasColumnName("event_type").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.CorrelationKey).HasColumnName("correlation_key").HasMaxLength(120);
            builder.Property(entry => entry.PayloadText).HasColumnName("payload_txt").IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.AttemptNumber).HasColumnName("attempt_no");
            builder.Property(entry => entry.AvailableAtUtc).HasColumnName("available_at");
            builder.Property(entry => entry.PublishedAtUtc).HasColumnName("published_at");
            builder.Property(entry => entry.PublishedByProcess).HasColumnName("published_by_process").HasMaxLength(60);
            builder.Property(entry => entry.LastErrorText).HasColumnName("last_error_txt").HasMaxLength(1000);
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });

        modelBuilder.Entity<InboxMessage>(builder =>
        {
            builder.ToTable("int_inbox_msg");
            builder.HasKey(entry => entry.Id);
            builder.Property(entry => entry.Id).HasColumnName("int_inbox_msg_id");
            builder.Property(entry => entry.MessageNumber).HasColumnName("message_no").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.IntegrationEndpointId).HasColumnName("int_endpoint_reg_id");
            builder.Property(entry => entry.MessageType).HasColumnName("message_type").HasMaxLength(60).IsRequired();
            builder.Property(entry => entry.ExternalMessageId).HasColumnName("external_message_id").HasMaxLength(120);
            builder.Property(entry => entry.CorrelationKey).HasColumnName("correlation_key").HasMaxLength(120);
            builder.Property(entry => entry.PayloadText).HasColumnName("payload_txt").IsRequired();
            builder.Property(entry => entry.StatusCode).HasColumnName("status_code").HasMaxLength(30).IsRequired();
            builder.Property(entry => entry.AttemptNumber).HasColumnName("attempt_no");
            builder.Property(entry => entry.AvailableAtUtc).HasColumnName("available_at");
            builder.Property(entry => entry.ProcessedAtUtc).HasColumnName("processed_at");
            builder.Property(entry => entry.ProcessedByProcess).HasColumnName("processed_by_process").HasMaxLength(60);
            builder.Property(entry => entry.LastErrorText).HasColumnName("last_error_txt").HasMaxLength(1000);
            builder.Property(entry => entry.CreatedAtUtc).HasColumnName("created_at");
            builder.Property(entry => entry.CreatedByUserId).HasColumnName("created_by");
            builder.Property(entry => entry.UpdatedAtUtc).HasColumnName("updated_at");
            builder.Property(entry => entry.UpdatedByUserId).HasColumnName("updated_by");
        });
    }
}
