/**
 * COPPA Compliance Pack
 *
 * Children's Online Privacy Protection Act (15 USC 6501-6506).
 * Enacted 1998; FTC implementing regulation 16 CFR Part 312, amended
 * effective July 1, 2013 (2013 COPPA Rule). 2024 NPRM pending final
 * rule as of August 2025 (citation to verify on final effective date).
 *
 * COPPA governs the collection, use, and disclosure of personal
 * information from children under 13 by operators of websites and
 * online services directed to children, or by operators with actual
 * knowledge they are collecting from children under 13.
 *
 * Key obligations for AI systems:
 *
 *   - 16 CFR 312.5: Verifiable parental consent required before
 *     collecting any personal information from children under 13.
 *     AI systems must not collect, use, or disclose child personal
 *     information before consent is obtained. Fail-closed default.
 *   - 16 CFR 312.2 (definition of personal information): Name,
 *     address, online contact info, screen name, phone, SSN,
 *     persistent identifier (cookie, IP, device ID, customer number),
 *     photo/video/audio containing child's image or voice, geolocation,
 *     and any information combined with the above.
 *   - 16 CFR 312.4: Privacy notice to parents before collection.
 *   - 16 CFR 312.6: Parental access and deletion rights.
 *   - 16 CFR 312.7: No conditioning of participation on excessive
 *     data disclosure.
 *   - 16 CFR 312.8: Confidentiality and security of child data.
 *   - 16 CFR 312.10: Retention limited to reasonably necessary period.
 *   - 16 CFR 312.12: Operators responsible for COPPA compliance of
 *     third-party AI services used to collect child data.
 *   - FTC enforcement position (2024 NPRM, citation to verify on
 *     final rule): AI providers must not use personal information
 *     from child-flagged sessions to train or fine-tune models.
 *
 * School-consent model: Under 34 CFR 99.30 (FERPA), a school may
 * provide consent on behalf of parents for educational purposes.
 * This pack covers commercial COPPA consent outside the school-
 * official exception. For in-school use, the FERPA pack governs
 * and this pack's consent gate defers to FERPA school consent.
 *
 * Cross-pack interactions:
 *   - FERPA + COPPA: For under-13 students in school context, FERPA
 *     school-consent model satisfies COPPA parental consent (34 CFR
 *     99.30 + 16 CFR 312.5). Both packs must be active; COPPA is
 *     the enforcement baseline outside the school-official exception.
 *   - HIPAA + COPPA: In pediatric clinical settings, PHI from
 *     under-13 patients is double-covered. HIPAA governs the PHI;
 *     COPPA governs any online collection. Both packs must be active.
 *   - Common Rule + COPPA: Research involving under-13 subjects
 *     requires both parental permission (45 CFR 46 Subpart D) and
 *     COPPA parental consent (16 CFR 312.5). Neither satisfies the
 *     other; both gates must fire. A pediatric research + online
 *     collection context triggers COPPA + Common Rule + HIPAA
 *     simultaneously (TRIPLE_COVERAGE_ALERT).
 *   - Florida Student Privacy + COPPA: Florida K-12 students include
 *     children under 13. COPPA applies to any online AI system with
 *     actual knowledge it serves under-13 users; Florida Statute
 *     Section 1002.222 adds state-law operator obligations.
 *
 * UF Health exposure: UF Health Shands Children's Hospital patient
 * portal AI and UF-affiliated K-12 research programs create direct
 * COPPA exposure. At $51,744/day per violation (FTC civil penalty
 * as of 2024; citation to verify current inflation-adjusted figure
 * per 15 USC 6502(c) and 16 CFR 1.98), a 30-day undetected
 * exposure in a pediatric portal equals roughly $1.55M before state
 * AG action.
 *
 * Sovereignty: US Federal.
 *
 * @connexum/ai-governance
 */
/**
 * COPPA category classifiers for the pack-driven classifier (W1).
 */
export const COPPA_CATEGORY_CLASSIFIERS = {
    UNDER_13_USER: {
        references: ['16 CFR 312.2 -- definition of child (under 13); 15 USC 6501(1)'],
        classifier: (input) => {
            // Direct age-under-13 declarations
            if (/\b(?:age[_\-\s]?(?:is\s+)?(?:\d|1[012])\b|under\s*13|age\s*[<:=]\s*(?:\d|1[012])\b)/i.test(input))
                return true;
            // DOB patterns suggesting born after 2013 (would still be under 13 in 2026)
            if (/\b(?:dob|date.of.birth|born)\s*[=:]\s*20(?:1[3-9]|2[0-6])/i.test(input))
                return true;
            // Explicit UNDER_13 flag or child marker
            if (/\b(?:UNDER_13_USER|child.user|pediatric.patient|minor.user)\b/i.test(input))
                return true;
            // K-2 grade level (reliably under 13)
            if (/\bgrade\s*[kK12](?:\b|,)|\bkindergarten\b/i.test(input))
                return true;
            return false;
        },
    },
    CHILD_DIRECTED_CONTEXT: {
        references: ['16 CFR 312.2 -- operator definition; FTC child-directed test'],
        classifier: (input) => {
            if (/\b(?:child.directed|children.?s\s+(?:app|service|website|platform)|pediatric\s+(?:portal|app|service))\b/i.test(input))
                return true;
            if (/\bCHILD_DIRECTED_CONTEXT\b/i.test(input))
                return true;
            return false;
        },
    },
    PARENTAL_CONSENT_PENDING: {
        references: ['16 CFR 312.5 -- verifiable parental consent required before collection'],
        classifier: (input) => {
            if (/\b(?:parental.consent.pending|consent.not.obtained|awaiting.parent.approval|PARENTAL_CONSENT_PENDING)\b/i.test(input))
                return true;
            return false;
        },
    },
    PERSISTENT_IDENTIFIER_FROM_CHILD: {
        references: ['16 CFR 312.2 -- persistent identifier is personal information'],
        classifier: (input) => {
            // Session/device identifiers combined with child context indicator
            if (/\b(?:session.token|device.id|cookie.id|tracking.id)\b.*\b(?:child|under.13|minor|age\s*[<:]\s*1[0-3])\b/i.test(input))
                return true;
            if (/\b(?:child|under.13|minor)\b.*\b(?:session.token|device.id|cookie.id|persistent.identifier)\b/i.test(input))
                return true;
            if (/\bPERSISTENT_IDENTIFIER_FROM_CHILD\b/i.test(input))
                return true;
            return false;
        },
    },
    CHILD_VOICE_OR_IMAGE: {
        references: ['16 CFR 312.2 -- photo, video, audio of child is personal information (2013 Rule)'],
        classifier: (input) => {
            if (/\b(?:child.voice|child.image|child.photo|child.video|audio.from.child|biometric.child|CHILD_VOICE_OR_IMAGE)\b/i.test(input))
                return true;
            return false;
        },
    },
    CHILD_GEOLOCATION: {
        references: ['16 CFR 312.2 -- geolocation of minors; FTC high-sensitivity treatment'],
        classifier: (input) => {
            if (/\b(?:child.location|minor.geolocation|kid.gps|student.location|CHILD_GEOLOCATION)\b/i.test(input))
                return true;
            // Geolocation pattern combined with child/minor indicator
            if (/\b(?:lat|latitude|longitude|gps.coords)\b.*\b(?:child|minor|under.13)\b/i.test(input))
                return true;
            return false;
        },
    },
    CHILD_HEALTH_DATA: {
        references: ['16 CFR 312.2 -- health information from child; HIPAA intersection in clinical settings'],
        classifier: (input) => {
            if (/\b(?:child.health|pediatric.diagnosis|minor.medical|child.patient.record|CHILD_HEALTH_DATA)\b/i.test(input))
                return true;
            // Health/diagnosis combined with under-13 or child context
            if (/\b(?:diagnosis|medication|allergy|condition|disorder)\b.*\b(?:child|minor|pediatric|under.13)\b/i.test(input))
                return true;
            return false;
        },
    },
    COPPA_CONSENT_RECORD: {
        references: ['16 CFR 312.10 -- retain consent records; FTC audit trail guidance'],
        classifier: (input) => {
            if (/\b(?:parental.consent.obtained|coppa.consent.record|verifiable.parental.consent|parent.approved|COPPA_CONSENT_RECORD)\b/i.test(input))
                return true;
            return false;
        },
    },
};
export const COPPA_PACK = {
    categoryClassifiers: COPPA_CATEGORY_CLASSIFIERS,
    /**
     * P3.5: UNDER_13_USER, CHILD_HEALTH_DATA, CHILD_VOICE_OR_IMAGE,
     * CHILD_GEOLOCATION, and PERSISTENT_IDENTIFIER_FROM_CHILD are
     * inherently subject-keyed. Each event must carry a data subject ID
     * to satisfy FTC audit trail requirements and COPPA enforcement
     * record-keeping expectations.
     */
    subjectKeyedCategories: [
        'UNDER_13_USER',
        'CHILD_HEALTH_DATA',
        'CHILD_VOICE_OR_IMAGE',
        'CHILD_GEOLOCATION',
        'PERSISTENT_IDENTIFIER_FROM_CHILD',
    ],
    id: 'coppa',
    name: 'COPPA (Children\'s Online Privacy Protection Act)',
    version: '1.0.0',
    description: 'Children\'s Online Privacy Protection Act (15 USC 6501-6506; 16 CFR Part 312) compliance for AI systems that may collect personal information from children under 13. Covers verifiable parental consent gate, no-training-on-child-inputs attestation, persistent identifier block before consent, child data retention limits (90 days), privacy notice to parents, parental access and deletion rights, and third-party AI vendor COPPA contract requirements. Designed for pediatric clinical AI (UF Health Shands Children\'s Hospital), K-12 edtech, and any consumer-facing AI with foreseeable under-13 users.',
    authority: 'Federal Trade Commission (FTC)',
    industries: ['pediatrics', 'edtech', 'k12', 'health-it', 'consumer-apps', 'higher-education'],
    requiredModules: [
        {
            name: 'governance-runtime',
            required: true,
            reason: 'Parental consent gate enforcement; age-gate before any collection; child-directed context controls; no-collection-before-consent rule',
            reference: '16 CFR 312.5 (verifiable parental consent); 16 CFR 312.7 (no excessive collection conditioning)',
        },
        {
            name: 'data-classifier',
            required: true,
            reason: 'Classify UNDER_13_USER, CHILD_DIRECTED_CONTEXT, PARENTAL_CONSENT_PENDING, and persistent identifiers; flag child health data for dual COPPA/HIPAA review',
            reference: '16 CFR 312.2 (definition of personal information from children); 15 USC 6501',
        },
        {
            name: 'audit-integrity',
            required: true,
            reason: 'Tamper-evident logs of all child data collection events; consent record preservation; deletion request audit trail',
            reference: '16 CFR 312.10 (retention); FTC enforcement pattern (3-year audit log standard)',
        },
        {
            name: 'encryption-layer',
            required: true,
            reason: 'Reasonable security procedures to protect confidentiality, security, and integrity of child personal information',
            reference: '16 CFR 312.8 (confidentiality and security requirements)',
        },
        {
            name: 'session-persistence',
            required: true,
            reason: 'Per-user parental consent status tracking; consent withdrawal tracking; child retention period tracking',
            reference: '16 CFR 312.5 (consent before collection); 16 CFR 312.6 (parental access rights)',
        },
        {
            name: 'supply-chain',
            required: true,
            reason: 'Third-party AI vendor COPPA contractual obligations; no-redisclosure terms; no-training-on-child-inputs attestation',
            reference: '16 CFR 312.12 (third-party service provider obligations)',
        },
        {
            name: 'approval-queue',
            required: true,
            reason: 'Parental consent review workflow; parental access and deletion request processing; child-directed context review before AI deployment',
            reference: '16 CFR 312.5 (consent gate); 16 CFR 312.6 (parental DSR)',
        },
        {
            name: 'attestation-manager',
            required: true,
            reason: 'Provider no-training-on-child-inputs attestation on file; COPPA vendor agreement documentation; privacy notice availability record',
            reference: '16 CFR 312.8 (reasonable security); 16 CFR 312.12 (vendor agreement)',
        },
        {
            name: 'transparency-injector',
            required: true,
            reason: 'Privacy notice to parents before collection begins; disclosure of AI use to parents in child-directed services',
            reference: '16 CFR 312.4 (privacy notice to parents)',
        },
        {
            name: 'event-bus',
            required: true,
            reason: 'Consent-grant and consent-withdrawal events; deletion-request events; breach detection for child data',
            reference: '16 CFR 312.6 (parental rights); FTC incident response guidance',
        },
    ],
    moduleConfig: {
        'data-classifier': {
            enabledCategories: [
                'UNDER_13_USER',
                'CHILD_DIRECTED_CONTEXT',
                'PARENTAL_CONSENT_PENDING',
                'PERSISTENT_IDENTIFIER_FROM_CHILD',
                'CHILD_VOICE_OR_IMAGE',
                'CHILD_GEOLOCATION',
                'CHILD_HEALTH_DATA',
                'COPPA_CONSENT_RECORD',
            ],
            under13Action: 'BLOCK',
            childDirectedAction: 'REQUIRE_APPROVAL',
        },
        'governance-runtime': {
            coppaParentalConsentGateEnabled: true,
            ageGateRequired: true,
            minimumCollectionEnforced: true,
        },
        'session-persistence': {
            parentalConsentStatusRequired: true,
            childRetentionDays: 90,
        },
        'supply-chain': {
            vendorCoppaAgreementOnFile: true,
            vendorNoTrainingOnChildInputsRequired: true,
            vendorNoRedisclosureOfChildDataRequired: true,
        },
        'approval-queue': {
            coppaParentalConsentGateEnabled: true,
            parentalDsrEnabled: true,
            childDirectedContextReviewRequired: true,
        },
        'attestation-manager': {
            providerTrainingProhibitionAttested: true,
            privacyNoticeActive: true,
        },
        'transparency-injector': {
            parentPrivacyNoticeRequired: true,
        },
    },
    providerPolicy: {
        blockedProviders: [],
        requiredCapabilities: [
            'ZERO-TRAINING-ON-CHILD-INPUTS',
            'CHILD-DATA-RETENTION-90-DAYS',
            'NO-REDISCLOSURE-CHILD-DATA',
            'COPPA-CONTRACT-ON-FILE',
        ],
        blockReasons: {},
    },
    dataPolicy: {
        scanCategories: [
            'UNDER_13_USER',
            'CHILD_DIRECTED_CONTEXT',
            'PARENTAL_CONSENT_PENDING',
            'PERSISTENT_IDENTIFIER_FROM_CHILD',
            'CHILD_VOICE_OR_IMAGE',
            'CHILD_GEOLOCATION',
            'CHILD_HEALTH_DATA',
            'COPPA_CONSENT_RECORD',
        ],
        categoryActions: {
            UNDER_13_USER: 'BLOCK',
            CHILD_DIRECTED_CONTEXT: 'REQUIRE_APPROVAL',
            PARENTAL_CONSENT_PENDING: 'BLOCK',
            PERSISTENT_IDENTIFIER_FROM_CHILD: 'BLOCK',
            CHILD_VOICE_OR_IMAGE: 'BLOCK',
            CHILD_GEOLOCATION: 'BLOCK',
            CHILD_HEALTH_DATA: 'BLOCK',
            COPPA_CONSENT_RECORD: 'LOG',
        },
        encryptionRequired: true,
        encryptionStandard: 'AES-256',
        minimumClassification: 'CONFIDENTIAL',
    },
    retentionPolicy: {
        sovereignty: ['US'],
        // 16 CFR 312.10: no longer than reasonably necessary for purpose.
        // FTC enforcement practice: 3-year audit log standard.
        // Child personal information: purge within 90 days of purpose fulfillment.
        // Consent records: retain 3 years after child data deletion.
        auditLogRetentionDays: 1095, // 3 years (FTC investigation standard)
        sessionRetentionDays: 90, // Max child data retention per FTC policy
        incidentRetentionDays: 1095, // 3 years (FTC enforcement practice)
        reference: '16 CFR 312.10 (no longer than reasonably necessary); FTC enforcement practice (3-year audit log)',
    },
    incidentPolicy: {
        // COPPA has no statutory breach notification clock. FTC enforcement
        // pattern: 72-hour internal escalation; parent notification within
        // 10 business days of confirmation.
        notificationDeadlineHours: 72,
        reference: 'FTC enforcement pattern (72-hour internal; 10 business-day parent notification); state COPPA-adjacent laws may impose shorter clocks (citation to verify)',
        requiredRecipients: ['ftc-bureau-consumer-protection', 'affected-parents-guardians', 'institution-privacy-officer'],
        formalNotificationRequired: true,
    },
    validators: [
        {
            id: 'coppa-parental-consent-gate',
            description: 'Parental consent verified before ANY collection from under-13 user',
            reference: '16 CFR 312.5 (verifiable parental consent)',
            check: 'coppa_parental_consent_gate_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'coppa-no-training-on-child-inputs',
            description: 'Provider attestation on file: no model training on child session data',
            reference: '16 CFR 312.8 (reasonable security); FTC 2024 NPRM (citation to verify on final rule)',
            check: 'coppa_no_training_on_child_inputs',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'coppa-persistent-id-block',
            description: 'Persistent identifiers not set for under-13 users before consent',
            reference: '16 CFR 312.2 (definition of personal information -- persistent identifier)',
            check: 'coppa_persistent_id_block_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'coppa-child-data-retention-limit',
            description: 'Child personal information purged within 90 days of purpose fulfillment',
            reference: '16 CFR 312.10 (retention limited to reasonably necessary period)',
            check: 'coppa_child_data_retention_limit',
            failSeverity: 'HIGH',
        },
        {
            id: 'coppa-privacy-notice-active',
            description: 'Privacy notice accessible to parents before collection begins',
            reference: '16 CFR 312.4 (privacy notice to parents)',
            check: 'coppa_privacy_notice_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'coppa-parental-access-rights',
            description: 'Mechanism exists for parents to review, correct, and delete child data',
            reference: '16 CFR 312.6 (parental access and deletion rights)',
            check: 'coppa_parental_access_rights',
            failSeverity: 'HIGH',
        },
        {
            id: 'coppa-vendor-agreement',
            description: 'Third-party AI vendor contractually bound to COPPA obligations',
            reference: '16 CFR 312.12 (third-party service provider obligations)',
            check: 'coppa_vendor_agreement',
            failSeverity: 'HIGH',
        },
        {
            id: 'coppa-behavioral-under13-block',
            description: 'Runtime blocks UNDER_13_USER category when no parental consent confirmed',
            reference: '16 CFR 312.5 (no collection before consent)',
            check: 'behavioralValidator_coppa',
            failSeverity: 'CRITICAL',
        },
    ],
};
//# sourceMappingURL=coppa.js.map