/**
 * TILA (Truth in Lending Act) + Regulation Z -- Non-TRID Provisions Pack
 *
 * Previously bundled with TRID in `src/packs/tila-trid.ts`. Split per Thomas's
 * 2026-04-24 principle: one country, one regulation, one pack. CFPB enforces
 * TRID and other-TILA provisions separately at 12 CFR §1026.
 *
 * Scope: Truth in Lending Act (15 USC §1601 et seq.) + Regulation Z
 * (12 CFR Part 1026) provisions OTHER than the integrated Loan Estimate /
 * Closing Disclosure rule (§1026.19(e)/(f)). This pack covers:
 *   - Right of rescission (12 CFR §1026.23): 3-business-day right for
 *     non-purchase-money refinances and HELOCs
 *   - Ability-to-Repay / Qualified Mortgage (12 CFR §1026.43): ATR
 *     determination requirements, QM safe harbor, debt-to-income analysis
 *   - Advertising trigger terms (12 CFR §§1026.16, 1026.24): closed-end
 *     and open-end credit advertising rules; if a trigger term is used,
 *     additional disclosures are required
 *   - Credit card disclosures (12 CFR §§1026.5-1026.16): account-opening,
 *     periodic statement, change-in-terms, over-limit disclosures
 *   - Consumer lease disclosures (12 CFR Part 1013): not Reg Z but handled
 *     here as TILA's statutory companion for consumer credit/lease boundary
 *   - ARM initial/periodic disclosures (12 CFR §§1026.19(b), 1026.20(d))
 *   - HELOC disclosures (12 CFR §1026.40)
 *
 * NOT in scope for this pack (see us-trid.ts):
 *   - Loan Estimate delivery / Closing Disclosure delivery (§1026.19(e)/(f))
 *   - Integrated disclosure form numeric fields (APR on LE/CD forms)
 *   - Changed-circumstance revised LE workflow
 *
 * Cross-pack interactions:
 *   - us-tila x us-trid: TRID is the integrated-disclosure subset of Reg Z;
 *     us-tila covers the rest. If both bind, TRID governs the integrated
 *     disclosure forms specifically; us-tila governs all other Reg Z obligations.
 *   - us-tila x us-respa: For mortgage servicing, both apply. RESPA Section 6
 *     QWR obligations and TILA right-of-rescission for modifications run in
 *     parallel. Strictest-wins on retention: RESPA 5-year governs over TILA
 *     3-year for shared mortgage records.
 *   - us-tila x us-trid x us-respa: For mortgage closings all three may
 *     activate. TILA rescission clock (§1026.23) and TRID LE/CD clocks
 *     (§1026.19(e)/(f)) run simultaneously; RESPA provides the QWR overlay.
 *
 * LLM-EGRESS PRIMACY RULES (Thomas directive 2026-04-22):
 *   - BLOCK: LLM from making ATR/QM determinations. The ATR determination
 *     (§1026.43) requires a documented reasonable good-faith belief by a
 *     licensed human; an LLM cannot be the sole or proximate source.
 *   - BLOCK: LLM from triggering rescission notice generation without human
 *     review. Rescission notices must accurately reflect the 3-day window.
 *   - REQUIRE GUARDRAILS: LLMs may draft advertising copy but trigger-term
 *     detection must fire; if a trigger term is present, full disclosure set
 *     must accompany the advertisement.
 *
 * @connexum/ai-governance
 */
/**
 * TILA (non-TRID) category classifiers.
 * Covers rescission, ATR/QM, advertising trigger terms, credit cards, leases.
 */
export const US_TILA_CATEGORY_CLASSIFIERS = {
    TILA_RESCISSION_NOTICE: {
        references: ['12 CFR §1026.23 -- right of rescission; 3-business-day window for non-purchase-money transactions'],
        classifier: (input) => {
            if (/\b(?:right\s+of\s+rescission|rescission\s+(?:notice|period|right|clock|form)|3.day\s+rescission|three.business.day\s+rescission)\b/i.test(input))
                return true;
            if (/\b(?:notice\s+of\s+right\s+to\s+cancel|1026\.23|TILA\s+rescission)\b/i.test(input))
                return true;
            return false;
        },
    },
    ATR_DETERMINATION: {
        references: ['12 CFR §1026.43 -- Ability-to-Repay / Qualified Mortgage rule; ATR determination'],
        classifier: (input) => {
            if (/\b(?:ability.to.repay|ATR\s+(?:determination|analysis|rule|test)|qualified\s+mortgage|QM\s+(?:safe\s+harbor|rule|test|status))\b/i.test(input))
                return true;
            if (/\b(?:debt.to.income|DTI\s+(?:ratio|limit|threshold|calculation)|43\s+percent\s+DTI|1026\.43)\b/i.test(input))
                return true;
            if (/\b(?:prepayment\s+penalty\s+test|points.and.fees\s+test|non.QM\s+loan|non.qualified\s+mortgage)\b/i.test(input))
                return true;
            return false;
        },
    },
    TILA_ADVERTISING_TRIGGER_TERM: {
        references: ['12 CFR §1026.24 (closed-end advertising); §1026.16 (open-end advertising) -- trigger terms requiring full disclosure set'],
        classifier: (input) => {
            // Closed-end trigger terms per §1026.24(b)
            if (/\b(?:down\s+payment\s+of\s+\$[\d,.]+|monthly\s+payment\s+of\s+\$[\d,.]+|finance\s+charge\s+of|amount\s+of\s+any\s+payment|number\s+of\s+payments)\b/i.test(input))
                return true;
            if (/\b(?:advertising\s+trigger\s+term|TILA\s+(?:ad|advertising)\s+rule|§1026\.24|§1026\.16|Reg\s+Z\s+ad(?:vertising)?)\b/i.test(input))
                return true;
            // APR used as trigger term in advertising
            if (/\b(?:annual\s+percentage\s+rate|APR)\b.{0,30}\b(?:ad(?:vertisement|s)?|market(?:ing)?|promot(?:ion|ional))\b/i.test(input))
                return true;
            return false;
        },
    },
    CREDIT_CARD_DISCLOSURE: {
        references: ['12 CFR §§1026.5-1026.16 -- open-end (credit card) disclosure requirements; periodic statements, change-in-terms'],
        classifier: (input) => {
            if (/\b(?:credit\s+card\s+(?:disclosure|agreement|statement|terms)|account.opening\s+disclosure|periodic\s+statement\s+(?:disclosure|requirement))\b/i.test(input))
                return true;
            if (/\b(?:change.in.terms\s+notice|over.limit\s+(?:fee|opt.in)|minimum\s+payment\s+disclosure|credit\s+card\s+act|CARD\s+Act)\b/i.test(input))
                return true;
            return false;
        },
    },
    CONSUMER_LEASE_DISCLOSURE: {
        references: ['15 USC §1667 (Consumer Leasing Act); 12 CFR Part 1013 (Regulation M) -- consumer lease disclosures'],
        classifier: (input) => {
            if (/\b(?:consumer\s+lease\s+(?:disclosure|agreement|term)|Regulation\s+M|Reg\s+M\s+disclosure|residual\s+value\s+disclosure|lease\s+capitalized\s+cost)\b/i.test(input))
                return true;
            if (/\b(?:12\s+CFR\s+(?:Part\s+)?1013|Consumer\s+Leasing\s+Act|§1667)\b/i.test(input))
                return true;
            return false;
        },
    },
    CREDENTIALS: {
        references: ['TILA/Reg Z -- information security for disclosure delivery systems'],
        classifier: (input) => {
            if (/\b(?:api[_-]?key|apikey)\s*[=:]\s*["']?[A-Za-z0-9_\-\/+]{16,}["']?/i.test(input))
                return true;
            if (/\bpassword\s*[=:]\s*["']?[A-Za-z0-9!@#$%^&*_\-]{8,}["']?/i.test(input))
                return true;
            if (/\bAKIA[A-Z0-9]{16}\b/.test(input))
                return true;
            if (/-----BEGIN\s+(?:RSA\s+)?PRIVATE\s+KEY-----/.test(input))
                return true;
            return false;
        },
    },
};
export const US_TILA_PACK = {
    categoryClassifiers: US_TILA_CATEGORY_CLASSIFIERS,
    subjectKeyedCategories: ['TILA_RESCISSION_NOTICE', 'ATR_DETERMINATION'],
    id: 'us-tila',
    /** GAP-S1-01: MT-03b is the site/packs.html public code for this pack. */
    aliases: ['MT-03b'],
    name: 'TILA / Regulation Z (Non-TRID Provisions)',
    version: '1.0.0',
    description: 'Truth in Lending Act (15 USC §1601, Regulation Z 12 CFR Part 1026) LLM-egress policy covering all Reg Z provisions other than the integrated TRID disclosure forms. Blocks LLMs from making Ability-to-Repay/QM determinations. Gates rescission notice generation. Detects advertising trigger terms and requires full disclosure set. Covers credit-card disclosures, consumer leases, ARM/HELOC disclosures. For TRID integrated disclosure forms (LE/CD), use us-trid.',
    authority: 'Consumer Financial Protection Bureau (CFPB)',
    industries: ['mortgage-lender', 'bank', 'credit-union', 'auto-finance', 'bnpl', 'heloc-lender', 'fintech-lender', 'credit-card-issuer'],
    requiredModules: [
        {
            name: 'governance-runtime',
            required: true,
            reason: 'Block LLM ATR/QM determinations; gate rescission notice generation; enforce ARM/HELOC disclosure requirements',
            reference: '12 CFR §1026.23 (rescission); §1026.43 (ATR/QM); §§1026.19(b), 1026.20(d) (ARM); §1026.40 (HELOC)',
        },
        {
            name: 'data-classifier',
            required: true,
            reason: 'Detect TILA_RESCISSION_NOTICE, ATR_DETERMINATION, TILA_ADVERTISING_TRIGGER_TERM, CREDIT_CARD_DISCLOSURE, CONSUMER_LEASE_DISCLOSURE categories before LLM egress',
            reference: '12 CFR §1026.23; §1026.43; §§1026.16, 1026.24; §§1026.5-1026.16; Part 1013',
        },
        {
            name: 'audit-integrity',
            required: true,
            reason: 'Tamper-evident audit trail for all TILA egress decisions, ATR block events, rescission clock events, advertising trigger detections',
            reference: '12 CFR §1026.25(a) -- 3-year retention for most TILA records',
        },
        {
            name: 'approval-queue',
            required: true,
            reason: 'Named human must review ATR determination before loan approval; rescission notice must be human-verified before delivery',
            reference: '12 CFR §1026.43(c) (ATR good-faith reasonable determination); §1026.23 (rescission notice)',
        },
        {
            name: 'event-bus',
            required: true,
            reason: 'Rescission 3-business-day clock; ARM annual disclosure trigger; change-in-terms advance notice clock (45 days)',
            reference: '12 CFR §1026.23(a)(3) (3-day rescission); §1026.20(d) (annual ARM); §1026.9(c) (change-in-terms 45-day)',
        },
        {
            name: 'session-persistence',
            required: true,
            reason: 'Per-loan rescission clock state; ATR documentation record across agent restarts',
            reference: '12 CFR §1026.43(e) (QM safe harbor documentation); §1026.25 retention',
        },
        {
            name: 'transparency-injector',
            required: true,
            reason: 'Required disclosure when AI drafts advertising copy with trigger terms; ARM rate-cap disclosure injection; credit-card change-in-terms transparency',
            reference: '12 CFR §1026.24 (closed-end advertising); §1026.16 (open-end advertising); §1026.19(b) (ARM)',
        },
        {
            name: 'attestation-manager',
            required: true,
            reason: 'ATR methodology documentation per loan type; ARM disclosure methodology documentation; vendor attestation for any LLM used in credit underwriting',
            reference: '12 CFR §1026.43(c)(3) (ATR factors); §1026.17(g) (disclosures methodology)',
        },
        {
            name: 'anomaly-detector',
            required: true,
            reason: 'Detect advertising trigger terms in AI-generated marketing copy; detect ATR bypass patterns; detect unsanctioned LLM credit decisions',
            reference: '12 CFR §1026.24 (TILA advertising); §1026.43 (ATR); CFPB examination procedures',
        },
        {
            name: 'supply-chain',
            required: true,
            reason: 'Third-party vendors in credit underwriting or advertising must be attested; LLM providers must certify no ATR/QM determination capability',
            reference: '12 CFR §1026.43(c) (ATR -- creditor responsibility); §1026.17(c)',
        },
    ],
    moduleConfig: {
        'governance-runtime': {
            atrQmLlmDeterminationBlocked: true,
            rescissionNoticeLlmGenerationRequiresHumanReview: true,
            armDisclosureGateRequired: true,
            helocDisclosureGateRequired: true,
            advertisingTriggerTermDetectionActive: true,
            rescissionPeriodBusinessDays: 3,
        },
        'data-classifier': {
            enabledCategories: [
                'TILA_RESCISSION_NOTICE',
                'ATR_DETERMINATION',
                'TILA_ADVERTISING_TRIGGER_TERM',
                'CREDIT_CARD_DISCLOSURE',
                'CONSUMER_LEASE_DISCLOSURE',
                'CREDENTIALS',
            ],
            tilaRescissionNoticeAction: 'REQUIRE_HUMAN_REVIEW',
            atrDeterminationAction: 'BLOCK_LLM_DETERMINE',
            tilaAdvertisingTriggerTermAction: 'WARN_REQUIRE_FULL_DISCLOSURE',
            creditCardDisclosureAction: 'LOG',
            consumerLeaseDisclosureAction: 'LOG',
        },
        'approval-queue': {
            atrDeterminationRequiresHumanReview: true,
            rescissionNoticeRequiresHumanReview: true,
            armDisclosureRequiresHumanReview: true,
        },
        'event-bus': {
            rescissionClockActive: true,
            rescissionBusinessDays: 3,
            armAnnualDisclosureTriggerActive: true,
            changeInTerms45DayClockActive: true,
        },
        'session-persistence': {
            rescissionStateRequired: true,
            atrDocumentationRecordRequired: true,
        },
        'attestation-manager': {
            atrMethodologyDocumentationRequired: true,
            armDisclosureMethodologyDocumentationRequired: true,
            llmProviderCreditDecisionProhibitionAttestation: true,
        },
        'anomaly-detector': {
            advertisingRuleViolationDetectionActive: true,
            atrBypassPatternDetectionActive: true,
        },
        'transparency-injector': {
            advertisingTriggerTermFullDisclosureInjectionRequired: true,
            armRateCapDisclosureInjectionRequired: true,
        },
        'supply-chain': {
            creditUnderwritingVendorAttestationRequired: true,
        },
    },
    providerPolicy: {
        blockedProviders: [],
        requiredCapabilities: ['NO-TILA-ATR-DETERMINATION', 'AUDIT-LOGGING'],
        blockReasons: {},
    },
    dataPolicy: {
        scanCategories: [
            'TILA_RESCISSION_NOTICE',
            'ATR_DETERMINATION',
            'TILA_ADVERTISING_TRIGGER_TERM',
            'CREDIT_CARD_DISCLOSURE',
            'CONSUMER_LEASE_DISCLOSURE',
            'CREDENTIALS',
        ],
        categoryActions: {
            TILA_RESCISSION_NOTICE: 'LOG',
            ATR_DETERMINATION: 'BLOCK',
            TILA_ADVERTISING_TRIGGER_TERM: 'WARN',
            CREDIT_CARD_DISCLOSURE: 'LOG',
            CONSUMER_LEASE_DISCLOSURE: 'LOG',
            CREDENTIALS: 'BLOCK',
        },
        encryptionRequired: true,
        encryptionStandard: 'AES-256',
        minimumClassification: 'CONFIDENTIAL',
    },
    retentionPolicy: {
        // 3 years for most TILA records per 12 CFR §1026.25(a).
        // If us-respa also active, RESPA 5-year governs via strictest-wins.
        auditLogRetentionDays: 1095,
        sessionRetentionDays: 1095,
        incidentRetentionDays: 1095,
        reference: '12 CFR §1026.25(a) -- 3-year retention for most TILA records from consummation, action taken, or required action date.',
        forceDelete: false,
        requiresLegalHoldSupport: true,
        sovereignty: ['us'],
    },
    incidentPolicy: {
        // No statutory individual notification specifically for TILA/Reg Z;
        // GLBA / state law governs data breach notification.
        // Internal 72h escalation for ATR bypass (material underwriting failure).
        notificationDeadlineHours: 72,
        reference: '12 CFR §1026.43 -- LLM-sourced ATR determination is a material underwriting failure; 72h internal escalation; consumer notification via GLBA/state law.',
        requiredRecipients: ['compliance-officer', 'general-counsel', 'cfpb-if-examined'],
        formalNotificationRequired: true,
    },
    validators: [
        {
            id: 'us-tila-atr-llm-block',
            description: 'ATR/QM determination cannot be made by or sourced from an LLM; licensed human underwriter must make the ATR determination',
            reference: '12 CFR §1026.43(c) -- ATR good-faith reasonable determination by creditor',
            check: 'us_tila_atr_llm_block_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'us-tila-rescission-clock',
            description: '3-business-day right of rescission clock active for applicable non-purchase-money transactions',
            reference: '12 CFR §1026.23 (right of rescission for non-purchase money mortgage, HELOC)',
            check: 'us_tila_rescission_clock_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'us-tila-advertising-trigger-term',
            description: 'Advertising trigger-term detection active; AI-generated marketing copy checked for trigger terms requiring full disclosure set',
            reference: '12 CFR §1026.24 (closed-end credit advertising); §1026.16 (open-end credit advertising)',
            check: 'us_tila_advertising_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'us-tila-arm-disclosure',
            description: 'ARM initial and annual periodic disclosure gate active; CHARM booklet delivery tracked',
            reference: '12 CFR §1026.19(b) (ARM initial disclosure); §1026.20(d) (annual ARM periodic)',
            check: 'us_tila_arm_disclosure_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'us-tila-heloc-disclosure',
            description: 'HELOC disclosure gate active; account-opening disclosure and change-in-terms requirements enforced',
            reference: '12 CFR §1026.40 (HELOC disclosures)',
            check: 'us_tila_heloc_disclosure_active',
            failSeverity: 'MEDIUM',
        },
        {
            id: 'us-tila-audit-trail',
            description: 'Tamper-evident audit trail for all TILA egress decisions, ATR blocks, and rescission events',
            reference: '12 CFR §1026.25(a) -- 3-year retention',
            check: 'audit_trail_exists',
            failSeverity: 'HIGH',
        },
    ],
};
//# sourceMappingURL=us-tila.js.map