/**
 * Adults with Incapacity (Scotland) Act 2000 Compliance Pack
 *
 * Statute: Adults with Incapacity (Scotland) Act 2000 (asp 4) — the
 *   primary Scottish statute governing decision-making on behalf of
 *   adults aged 16+ who lack capacity. Distinct from the GB Mental
 *   Capacity Act 2005 (which does NOT apply in Scotland).
 *
 * Jurisdiction: Scotland
 * Authority:
 *   - Office of the Public Guardian (Scotland) — registers powers of
 *     attorney + intervention orders
 *   - Mental Welfare Commission for Scotland — statutory safeguarding
 *   - Sheriff Courts — appoint guardians + grant intervention orders
 *   - Scottish Government Adult Social Care directorate
 *
 * Why this pack (separate from GB / NI consent regimes):
 *   - England + Wales use the Mental Capacity Act 2005 (MCA);
 *   - Northern Ireland uses the Mental Capacity (NI) Act 2016 (partly
 *     in force);
 *   - Scotland uses AWI 2000 with its own distinctive five principles
 *     and a different framework for proxy decision-making.
 *   - AI agents that take decisions affecting adults in Scotland with
 *     impaired capacity must satisfy AWI 2000 — not MCA 2005.
 *
 * Five AWI principles (s.1):
 *   1. **Benefit** — any intervention must benefit the adult
 *   2. **Minimum intervention** — least restrictive option
 *   3. **Account of present and past wishes** — the adult's wishes
 *      (current and historic) considered
 *   4. **Consultation with relevant others** — nearest relative, primary
 *      carer, named person, attorney, guardian
 *   5. **Encourage adult to use existing skills and develop new skills**
 *
 * Decision-making instruments under the Act:
 *   - **Continuing Power of Attorney (CPOA)** — financial decisions
 *   - **Welfare Power of Attorney (WPOA)** — health/welfare decisions
 *   - **Intervention Order** — one-off decisions by the Sheriff
 *   - **Guardianship Order** — ongoing decisions by an appointed guardian
 *   - **Section 47 medical-treatment certificate** — treating clinician
 *     authorises medical treatment for incapacitated adult
 *   - **Section 13ZA** — community-care arrangements without formal
 *     guardianship in some cases
 *
 * AI-specific overlays:
 *   - Capacity-impacted-decision detection: AI agent must flag when an
 *     interaction is being made with or on behalf of an adult whose
 *     capacity is questioned, and route per AWI principles
 *   - Five-principles gate: principle-by-principle attestation captured
 *     for AWI-scope decisions
 *   - Proxy authority verification: attorney/guardian/intervention-order
 *     authority validated against the Office of the Public Guardian
 *     register before AI executes a proxy-authorised action
 *   - Consultation evidence: AI agent surfaces consultation duty (s.1(4))
 *     to the human reviewer
 *   - Section 47 certificate awareness: medical-treatment-context AI
 *     decisions check for an active s.47 certificate and treating-
 *     clinician identity
 *
 * Out of scope:
 *   - GB Mental Capacity Act 2005 (separate jurisdiction)
 *   - NI Mental Capacity Act 2016 (separate jurisdiction)
 *   - Scottish Mental Health Care and Treatment Act 2003 (different
 *     regime — compulsory treatment for mental disorder)
 *
 * @connexum/ai-governance
 */
export const SCOTLAND_AWI_CATEGORY_CLASSIFIERS = {
    AWI_PRINCIPLE_EVIDENCE: {
        references: [
            'AWI 2000 s.1 — five principles',
        ],
        classifier: (input) => {
            if (/\b(?:awi\s+(?:principle|s\.?\s*1)|adults\s+with\s+incapacity\s+(?:principle|scotland))\b/i.test(input))
                return true;
            if (/\b(?:benefit\s+principle\s+awi|minimum\s+intervention|present\s+and\s+past\s+wishes|consultation\s+with\s+relevant\s+others)\b/i.test(input))
                return true;
            return false;
        },
    },
    POWER_OF_ATTORNEY: {
        references: [
            'AWI 2000 ss.15-22 — Continuing + Welfare Power of Attorney',
        ],
        classifier: (input) => {
            if (/\b(?:continuing\s+power\s+of\s+attorney|welfare\s+power\s+of\s+attorney|cpoa|wpoa)\b/i.test(input))
                return true;
            if (/\b(?:opg\s+scotland\s+register|public\s+guardian\s+scotland|attorney\s+register\s+scotland)\b/i.test(input))
                return true;
            return false;
        },
    },
    INTERVENTION_ORDER: {
        references: [
            'AWI 2000 ss.53-56 — intervention orders',
        ],
        classifier: (input) => {
            if (/\b(?:intervention\s+order\s+(?:scotland|awi)|sheriff\s+intervention\s+order)\b/i.test(input))
                return true;
            if (/\b(?:s\.?\s*53\s+intervention|section\s+53\s+awi)\b/i.test(input))
                return true;
            return false;
        },
    },
    GUARDIANSHIP_ORDER: {
        references: [
            'AWI 2000 Part 6 — guardianship orders',
        ],
        classifier: (input) => {
            if (/\b(?:guardianship\s+order\s+(?:scotland|awi)|appointed\s+guardian\s+awi)\b/i.test(input))
                return true;
            if (/\b(?:welfare\s+guardian|financial\s+guardian|joint\s+guardian\s+awi)\b/i.test(input))
                return true;
            return false;
        },
    },
    S47_MEDICAL_CERTIFICATE: {
        references: [
            'AWI 2000 s.47 — medical-treatment certificate',
        ],
        classifier: (input) => {
            if (/\b(?:s\.?\s*47\s+(?:certificate|medical|treatment)|section\s+47\s+awi)\b/i.test(input))
                return true;
            if (/\b(?:medical\s+treatment\s+certificate\s+(?:scotland|awi)|treating\s+clinician\s+s47)\b/i.test(input))
                return true;
            return false;
        },
    },
    CAPACITY_ASSESSMENT: {
        references: [
            'AWI 2000 capacity-assessment evidence; Mental Welfare Commission guidance',
        ],
        classifier: (input) => {
            if (/\b(?:capacity\s+(?:assessment|test|determination|review)\s+(?:scotland|awi)|incapacity\s+evidence)\b/i.test(input))
                return true;
            if (/\b(?:mental\s+welfare\s+commission|mwc\s+visit|mwc\s+investigation)\b/i.test(input))
                return true;
            return false;
        },
    },
    CREDENTIALS: {
        references: ['Cross-pack secrets safety; AWI artefacts must not embed credentials'],
        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 (/-----BEGIN\s+(?:RSA\s+)?PRIVATE\s+KEY-----/.test(input))
                return true;
            return false;
        },
    },
};
export const SCOTLAND_AWI_PACK = {
    categoryClassifiers: SCOTLAND_AWI_CATEGORY_CLASSIFIERS,
    id: 'scotland-awi',
    aliases: [
        'scotland-awi-act',
        'awi-scotland',
        'adults-with-incapacity-scotland',
        'awi-2000',
    ],
    name: 'Adults with Incapacity (Scotland) Act 2000',
    version: '1.0.0',
    contentHash: '9d01c04d715668c1cb9ceedaeade2e2ecec3d12733f997ed69cad0ccd8aaff9e',
    description: 'Scottish statute governing decisions on behalf of adults aged 16+ who lack capacity. Distinct from GB Mental Capacity Act 2005 (does NOT apply in Scotland). Five principles (benefit, minimum intervention, present + past wishes, consultation, skills development). Covers Continuing/Welfare Power of Attorney, Intervention Orders, Guardianship Orders, s.47 medical-treatment certificates. AI agents acting in Scotland on or for adults with impaired capacity must satisfy AWI principles, not MCA. Pairs with `uk-gdpr` (UK-wide personal data); does NOT pair with `uk-equality-act` capacity provisions (different jurisdiction).',
    authority: 'Office of the Public Guardian (Scotland) + Mental Welfare Commission for Scotland + Sheriff Courts + Scottish Government Adult Social Care',
    industries: ['healthcare', 'social-care', 'public-sector', 'financial-services', 'legal'],
    requiredModules: [
        {
            name: 'governance-runtime',
            required: true,
            reason: 'Default-deny on AI actions made on behalf of an adult with impaired capacity unless five-principles attestation captured + proxy authority verified.',
            reference: 'AWI 2000 s.1; ss.15-22, 47, 53-56, Part 6',
        },
        {
            name: 'attestation-manager',
            required: true,
            reason: 'Five-principles attestation per AWI-scope decision; proxy-authority record (CPOA / WPOA / intervention order / guardianship); s.47 certificate registration; Mental Welfare Commission engagement.',
            reference: 'AWI 2000 s.1 + decision-making instruments',
        },
        {
            name: 'approval-queue',
            required: true,
            reason: 'T2 named-clinician / named-attorney / named-guardian sign-off on AWI-scope decisions; s.47 medical-treatment certificate sign-off; intervention-order / guardianship-bounded decisions reviewed.',
            reference: 'AWI 2000 named-role decision-making',
        },
        {
            name: 'audit-integrity',
            required: true,
            reason: 'Tamper-evident audit chain for capacity assessments, principle-attestation events, proxy-authority verifications, s.47 certificate sign-off, MWC engagement — required for Sheriff Court evidence + MWC investigation.',
            reference: 'AWI 2000 evidentiary requirements',
        },
        {
            name: 'data-classifier',
            required: true,
            reason: 'Surface AWI evidence categories for the audit chain and the dashboard.',
            reference: 'AWI 2000 evidence categorisation',
        },
        {
            name: 'agent-auth',
            required: true,
            reason: 'Proxy-authority binding: validate attorney/guardian/intervention-order authority against OPG (Scotland) register before AI executes a proxy-authorised action.',
            reference: 'AWI 2000 Office of the Public Guardian register',
        },
        {
            name: 'transparency-injector',
            required: true,
            reason: 'Adult-facing communication adapted to capacity (s.1(5) skills-development principle); consultation-with-relevant-others evidence surfaced.',
            reference: 'AWI 2000 s.1(5), s.1(4)',
        },
        {
            name: 'session-persistence',
            required: true,
            reason: 'Capacity assessments + principle-attestation + s.47 certificates retained for the adult\'s lifetime + 6 years (Sheriff Court evidence; medical-record alignment).',
            reference: 'AWI 2000 + Public Records (Scotland) Act 2011',
        },
        {
            name: 'event-bus',
            required: true,
            reason: 'Mental Welfare Commission notification routing; Sheriff Court update routing; capacity-change event detection; OPG register-update events.',
            reference: 'Mental Welfare Commission notification pathway',
        },
        {
            name: 'supply-chain',
            required: true,
            reason: 'Sub-supplier AWI awareness flow-down (financial / care providers); proxy-authority validation on third-party APIs.',
            reference: 'AWI 2000 sub-supplier accountability',
        },
    ],
    moduleConfig: {
        'governance-runtime': {
            awiFivePrinciplesGateRequired: true,
            proxyAuthorityVerificationRequired: true,
            defaultDenyOnUnverifiedProxyAuthority: true,
        },
        'attestation-manager': {
            principleAttestationRequired: true,
            proxyAuthorityRecordRequired: true,
            s47CertificateRegistrationRequired: true,
            mwcEngagementRecorded: true,
        },
        'approval-queue': {
            awiSignOffRequired: true,
            s47SignOffRequired: true,
            reviewTier: 'T2',
            reviewerCompetence: 'AWI_NAMED_AUTHORITY',
        },
        'audit-integrity': {
            sheriffCourtEvidenceTrackingRequired: true,
            mwcInvestigationEvidenceTrackingRequired: true,
        },
        'data-classifier': {
            enabledCategories: [
                'AWI_PRINCIPLE_EVIDENCE',
                'POWER_OF_ATTORNEY',
                'INTERVENTION_ORDER',
                'GUARDIANSHIP_ORDER',
                'S47_MEDICAL_CERTIFICATE',
                'CAPACITY_ASSESSMENT',
                'CREDENTIALS',
            ],
            credentialsAction: 'BLOCK',
        },
        'agent-auth': {
            opgScotlandRegisterValidationRequired: true,
            proxyAuthorityIdentityBindingRequired: true,
        },
        'transparency-injector': {
            adultFacingCommunicationCapacityAdaptedRequired: true,
            consultationEvidenceSurfacedRequired: true,
        },
        'session-persistence': {
            retentionDaysAfterAdultDeath: 2190, // 6 years post-death
            lifetimeRetentionForCapacityAssessments: true,
        },
        'event-bus': {
            mwcNotificationRoutingRequired: true,
            sheriffCourtUpdateRoutingRequired: true,
            capacityChangeDetectionRequired: true,
        },
        'supply-chain': {
            subSupplierAwiAwarenessFlowDownRequired: true,
        },
    },
    providerPolicy: {
        blockedProviders: ['deepseek', 'baidu', 'alibaba'],
        requiredCapabilities: ['DATA-RESIDENCY-UK-OR-EU', 'PROCESSOR-CONTRACT'],
        blockReasons: {
            deepseek: 'PRC jurisdiction. AWI evidence chain (capacity assessments, proxy-authority validations) must be UK-resident; Sheriff Court evidence chain requires it.',
            baidu: 'PRC jurisdiction. Inadequate evidence chain for Sheriff Court / MWC investigation.',
            alibaba: 'PRC jurisdiction. Inadequate evidence chain for Sheriff Court / MWC investigation.',
        },
    },
    dataPolicy: {
        scanCategories: [
            'AWI_PRINCIPLE_EVIDENCE',
            'POWER_OF_ATTORNEY',
            'INTERVENTION_ORDER',
            'GUARDIANSHIP_ORDER',
            'S47_MEDICAL_CERTIFICATE',
            'CAPACITY_ASSESSMENT',
            'CREDENTIALS',
        ],
        categoryActions: {
            AWI_PRINCIPLE_EVIDENCE: 'WARN',
            POWER_OF_ATTORNEY: 'WARN',
            INTERVENTION_ORDER: 'WARN',
            GUARDIANSHIP_ORDER: 'WARN',
            S47_MEDICAL_CERTIFICATE: 'WARN',
            CAPACITY_ASSESSMENT: 'WARN',
            CREDENTIALS: 'BLOCK',
        },
        encryptionRequired: true,
        encryptionStandard: 'AES-256-GCM',
        minimumClassification: 'RESTRICTED',
    },
    retentionPolicy: {
        auditLogRetentionDays: 3650, // 10 years (alongside medical record)
        sessionRetentionDays: 3650,
        incidentRetentionDays: 3650,
        reference: 'Public Records (Scotland) Act 2011; AWI 2000 evidentiary practice',
        forceDelete: false,
        requiresLegalHoldSupport: true,
        sovereignty: ['gb-sct', 'gb'],
    },
    incidentPolicy: {
        notificationDeadlineHours: 72,
        reference: 'Mental Welfare Commission notification pathway; AWI 2000 statutory safeguarding',
        requiredRecipients: ['mental-welfare-commission', 'office-of-public-guardian-scotland', 'sheriff-court', 'data-protection-officer'],
        formalNotificationRequired: true,
    },
    validators: [
        {
            id: 'scotland-awi-five-principles',
            description: 'Five AWI principles attested per scope decision: benefit + minimum intervention + present/past wishes + consultation + skills development.',
            reference: 'AWI 2000 s.1',
            check: 'attestation_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'scotland-awi-proxy-authority',
            description: 'Proxy authority (CPOA / WPOA / intervention order / guardianship) validated against OPG (Scotland) register before AI executes proxy-authorised action.',
            reference: 'AWI 2000 OPG register',
            check: 'governance_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'scotland-awi-s47-certificate',
            description: 's.47 medical-treatment certificate registered + treating clinician identified for medical-context AI decisions.',
            reference: 'AWI 2000 s.47',
            check: 'attestation_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'scotland-awi-capacity-assessment',
            description: 'Capacity assessment captured tamper-evidently; reviewer competence + assessment instrument recorded.',
            reference: 'AWI 2000 + Mental Welfare Commission guidance',
            check: 'audit_trail_exists',
            failSeverity: 'HIGH',
        },
        {
            id: 'scotland-awi-mwc-engagement',
            description: 'Mental Welfare Commission engagement record current; safeguarding-event reporting active.',
            reference: 'Mental Welfare Commission statutory pathway',
            check: 'monitoring_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'scotland-awi-consultation-evidence',
            description: 'Consultation with relevant others (s.1(4)) evidence captured; nearest relative / primary carer / named person / attorney / guardian engaged.',
            reference: 'AWI 2000 s.1(4)',
            check: 'attestation_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'scotland-awi-skills-development',
            description: 's.1(5) skills-development principle: adult-facing communication adapted to capacity; existing skills supported.',
            reference: 'AWI 2000 s.1(5)',
            check: 'transparency_active',
            failSeverity: 'MEDIUM',
        },
        {
            id: 'scotland-awi-supplier-flow-down',
            description: 'Sub-supplier AWI awareness recorded; proxy-authority validation enforced on third-party APIs.',
            reference: 'AWI 2000 sub-supplier accountability',
            check: 'subservice_registry_active',
            failSeverity: 'MEDIUM',
        },
        {
            id: 'scotland-awi-evidence-retention',
            description: 'AWI evidence retained 10 years (alongside medical record); legal-hold support active for live Sheriff Court / MWC matters.',
            reference: 'Public Records (Scotland) Act 2011',
            check: 'retention_policy_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'scotland-awi-encryption',
            description: 'AWI evidence chain encrypted at rest and in transit.',
            reference: 'UK GDPR Art. 32; AWI evidentiary integrity',
            check: 'encryption_active',
            failSeverity: 'MEDIUM',
        },
    ],
};
//# sourceMappingURL=scotland-awi.js.map