"""Read-only validation of the exact Task26 activation checklist."""

from __future__ import annotations

import hashlib
import json
from pathlib import Path

from checkin_cli.customer_admin import _read_activation_checklist
from checkin_cli.customer_coaching import load_customer_registry


PROFILE_ROOT = Path("/home/cube/.hermes/profiles/dualcoachtest").resolve()
REGISTRY_PATH = PROFILE_ROOT / "customers" / "registry.json"
CUSTOMER_KEY = "task26_live_2e_r2_20260815_8527916639"
DATA_ROOT = PROFILE_ROOT / "data" / "customers" / CUSTOMER_KEY
CHECKLIST_PATH = Path(__file__).with_name("activation-checklist-receipt.json")


def main() -> None:
    """Validate bindings through the production checklist parser."""
    registry = load_customer_registry(REGISTRY_PATH, PROFILE_ROOT)
    runtime = next(
        item for item in registry.customers if item.spec.customer_key == CUSTOMER_KEY
    )
    payload = _read_activation_checklist(
        CHECKLIST_PATH,
        PROFILE_ROOT,
        DATA_ROOT,
        REGISTRY_PATH,
        runtime.spec,
    )
    raw = CHECKLIST_PATH.read_bytes()
    print(
        json.dumps(
            {
                "schema": "task26-activation-checklist-validation-v1",
                "status": "PASS",
                "customer_key": runtime.spec.customer_key,
                "customer_enabled": runtime.spec.enabled,
                "checklist_sha256": hashlib.sha256(raw).hexdigest(),
                "token_rotated": payload["checklist"]["token_rotated"],
                "waiver_status": payload["checklist"]["token_rotation_waiver"][
                    "status"
                ],
            },
            sort_keys=True,
        )
    )


if __name__ == "__main__":
    main()
