{
  "schemaVersion": "1.0",
  "id": "child-pairing",
  "title": "Ghép máy của Bông",
  "purpose": "Guardian cấp proof một lần và TTL, không giả QR quét được.",
  "roles": [
    "adult",
    "guardian"
  ],
  "group": "members-children",
  "variantOf": null,
  "layout": {
    "canvas": {
      "width": 390,
      "height": 844
    },
    "responsive": {
      "minimumWidth": 360,
      "maximumWidth": 430,
      "scroll": "vertical",
      "safeAreaBottom": true,
      "fontScale": "native dynamic type; reflow without clipping",
      "keyboard": "composer sticky within resized viewport; dialog scrolls; no fixed keyboard overlay"
    },
    "regions": [
      {
        "id": "header",
        "order": 0,
        "type": "safe-area/header",
        "height": "intrinsic"
      },
      {
        "id": "content",
        "order": 1,
        "type": "purpose-specific pairing",
        "componentIds": [
          "screen-header",
          "child-pairing-0",
          "child-pairing-1",
          "child-pairing-2",
          "screen-actions"
        ]
      },
      {
        "id": "actions",
        "order": 2,
        "type": "one primary + secondary controls"
      },
      {
        "id": "navigation",
        "order": 3,
        "type": "none"
      }
    ]
  },
  "components": [
    {
      "id": "screen-header",
      "type": "Header",
      "props": {
        "homeLabel": "Nhà Lá",
        "scopeGate": "G exact child",
        "backTarget": "child-profile-detail",
        "settingsTarget": "settings"
      },
      "tokens": {
        "foreground": "{semantic.light.fg}",
        "darkForeground": "{semantic.dark.fg}"
      },
      "accessibility": {
        "label": "Thanh đầu màn hình",
        "readingOrder": 0,
        "focusOrder": "back then settings"
      }
    },
    {
      "id": "child-pairing-0",
      "type": "PairingProof",
      "props": {
        "contentText": "Mã ghép minh họa  472 816  Hạn mẫu: 10 phút · dùng một lần"
      },
      "tokens": {
        "background": "{semantic.light.surface}",
        "foreground": "{semantic.light.fg}",
        "darkBackground": "{semantic.dark.surface}",
        "darkForeground": "{semantic.dark.fg}",
        "bodySize": "{primitive.type.body}",
        "touchTarget": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Ghép máy của Bông · PairingProof",
        "readingOrder": 1,
        "colorOnly": false,
        "fontScaling": true,
        "minimumTouchTarget": 48,
        "instructions": "Đọc theo thứ tự; công bố nhãn trạng thái và lỗi, không chỉ màu."
      }
    },
    {
      "id": "child-pairing-1",
      "type": "Notice",
      "props": {
        "text": "Trên máy của Bông chọn “Nhập mã ghép”. Mã này chỉ dùng cho bản mẫu, không có QR thật.",
        "tone": ""
      },
      "tokens": {
        "background": "{semantic.light.surface}",
        "foreground": "{semantic.light.fg}",
        "darkBackground": "{semantic.dark.surface}",
        "darkForeground": "{semantic.dark.fg}",
        "bodySize": "{primitive.type.body}",
        "touchTarget": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Ghép máy của Bông · Notice",
        "readingOrder": 2,
        "colorOnly": false,
        "fontScaling": true,
        "minimumTouchTarget": 48,
        "instructions": "Đọc theo thứ tự; công bố nhãn trạng thái và lỗi, không chỉ màu."
      }
    },
    {
      "id": "child-pairing-2",
      "type": "SettingsGroup",
      "props": {
        "items": [
          {
            "label": "Quản lý thiết bị đã ghép",
            "description": "Thu hồi từng thiết bị",
            "target": "child-devices"
          }
        ]
      },
      "tokens": {
        "background": "{semantic.light.surface}",
        "foreground": "{semantic.light.fg}",
        "darkBackground": "{semantic.dark.surface}",
        "darkForeground": "{semantic.dark.fg}",
        "bodySize": "{primitive.type.body}",
        "touchTarget": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Ghép máy của Bông · SettingsGroup",
        "readingOrder": 3,
        "colorOnly": false,
        "fontScaling": true,
        "minimumTouchTarget": 48,
        "instructions": "Đọc theo thứ tự; công bố nhãn trạng thái và lỗi, không chỉ màu."
      }
    },
    {
      "id": "screen-actions",
      "type": "ActionGroup",
      "props": {
        "actions": [
          {
            "id": "navigate-0",
            "label": "Mở màn nhập mã mẫu",
            "kind": "navigate",
            "target": "child-pair-redeem",
            "confirmationRequired": false
          },
          {
            "id": "pair-child",
            "label": "Tạo mã mẫu mới",
            "kind": "mutate",
            "target": null,
            "confirmationRequired": false
          },
          {
            "id": "link-child-profile-detail",
            "label": "Bông",
            "kind": "navigate",
            "target": "child-profile-detail",
            "confirmationRequired": false
          },
          {
            "id": "link-settings",
            "label": "Cài đặt",
            "kind": "navigate",
            "target": "settings",
            "confirmationRequired": false
          },
          {
            "id": "link-child-devices",
            "label": "Máy của Bông",
            "kind": "navigate",
            "target": "child-devices",
            "confirmationRequired": false
          }
        ],
        "primaryCount": 1
      },
      "tokens": {
        "lightBackground": "{component.light.button.background}",
        "lightForeground": "{component.light.button.foreground}",
        "darkBackground": "{component.dark.button.background}",
        "darkForeground": "{component.dark.button.foreground}",
        "height": "{primitive.space.48}"
      },
      "accessibility": {
        "label": "Hành động của màn hình",
        "keyboard": true,
        "focusVisible": true,
        "disabledOnlyLowContrast": true
      }
    }
  ],
  "fields": [],
  "states": [
    {
      "id": "proof-active",
      "when": "G xác nhận profile active",
      "visibleUI": "One use, TTL10m",
      "availableActions": [
        "navigate-0",
        "pair-child",
        "link-child-profile-detail",
        "link-settings",
        "link-child-devices"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "expired",
      "when": "Hết TTL",
      "visibleUI": "Không redeem, tạo proof mới",
      "availableActions": [
        "navigate-0",
        "link-child-profile-detail",
        "link-settings",
        "link-child-devices"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "consumed",
      "when": "Máy đã redeem",
      "visibleUI": "Không phát token phụ huynh",
      "availableActions": [
        "navigate-0",
        "link-child-profile-detail",
        "link-settings",
        "link-child-devices"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "navigate-0",
      "label": "Mở màn nhập mã mẫu",
      "kind": "navigate",
      "targetScreenId": "child-pair-redeem",
      "permission": "G exact child",
      "confirmationRequired": false,
      "contractRef": "local navigation",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": null
    },
    {
      "id": "pair-child",
      "label": "Tạo mã mẫu mới",
      "kind": "mutate",
      "targetScreenId": null,
      "permission": "G exact child",
      "confirmationRequired": false,
      "contractRef": "POST /v1/households/{hid}/children/{mid}/pairings",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": "Stable actor/household/command key and canonical body; changed payload is a new confirmed intent."
    },
    {
      "id": "link-child-profile-detail",
      "label": "Bông",
      "kind": "navigate",
      "targetScreenId": "child-profile-detail",
      "permission": "G exact child",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-settings",
      "label": "Cài đặt",
      "kind": "navigate",
      "targetScreenId": "settings",
      "permission": "G exact child",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-child-devices",
      "label": "Máy của Bông",
      "kind": "navigate",
      "targetScreenId": "child-devices",
      "permission": "G exact child",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    }
  ],
  "dataBindings": [
    {
      "source": "POST /v1/households/{hid}/children/{mid}/pairings",
      "shape": {
        "pairing": "ChildPairingDto {pairing_id, child_member_id, token (one use, TTL; never log/persist in design), expires_at}",
        "redeemInput": "PairingRedeemInput {redemption_id (client-generated, reused on retry), token, device_label}",
        "prepared": "PairingPreparedDto {redemption_id, device_id, household_id, child_member_id, credential (SecureStore only), credential_version, device_version, recovery_expires_at}",
        "activateInput": "expected device_version"
      },
      "sample": {
        "pairing": {
          "pairing_id": "pairing-example",
          "child_member_id": "bong",
          "token": "omitted",
          "expires_at": "2026-10-14T05:10:00Z"
        },
        "redeemInput": {
          "redemption_id": "redeem-example",
          "token": "omitted",
          "device_label": "Máy của Bông"
        }
      },
      "sampleOnly": true,
      "actorConstraint": "exact actor allowlist",
      "envelope": "API refs use CommandEnvelope; local review context is not an API property."
    }
  ],
  "copy": {
    "heading": "Ghép máy của Bông",
    "primary": "Mở màn nhập mã mẫu",
    "empty": null,
    "notices": [
      "Trên máy của Bông chọn “Nhập mã ghép”. Mã này chỉ dùng cho bản mẫu, không có QR thật."
    ],
    "locale": "vi",
    "demoLabel": "Bản thiết kế · dữ liệu mẫu · không kết nối dịch vụ"
  },
  "implementation": {
    "nativeRoute": "/design/child-pairing",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [
      "POST /v1/households/{hid}/children/{mid}/pairings"
    ],
    "newContractRefs": [],
    "notes": [
      "Native QR dùng proof server trả, không embed auth parent. Never log proof.",
      "Tất cả ví dụ là dữ liệu thiết kế, không bằng chứng native/API/store đã chạy.",
      "Native route dưới đây là đề xuất mapping cho agent, không tuyên bố route source đã tồn tại.",
      "Mọi mutation dùng envelope {data,version,household_revision,replayed}, stable Idempotency-Key và expected_version khi sửa."
    ],
    "integrationStatus": "design complete; local static/draft interactions; native/API adapters pending",
    "sourceAuthority": [
      "docs/product-brief.md",
      "plans/261013-1409-sweepy-vietnam-mobile/mobile-flows.md",
      "plans/261013-1409-sweepy-vietnam-mobile/api-contracts.md",
      "packages/domain/src/contracts/phase2.ts",
      "packages/domain/src/index.ts",
      "packages/domain/src/contracts/phase3.ts",
      "packages/domain/src/contracts/billing.ts",
      "apps/mobile/src/lib/api.ts"
    ],
    "capability": "G exact child",
    "errors": {
      "401": "Stop queue; adult login or child re-pair without parent account.",
      "403": "Do not retry lost capability. FEATURE_REQUIRED never grants Pro.",
      "409": "Fetch canonical scoped state; review/reconfirm new intent, do not rewrite old replay payload.",
      "422": "Field error with retained draft.",
      "429": "Respect Retry-After.",
      "503": "Backoff only retryable commands with original key."
    }
  }
}
