{
  "schemaVersion": "1.0",
  "id": "child-pair-redeem",
  "title": "Nhập mã của phụ huynh",
  "purpose": "Unpaired device redeem, SecureStore rồi activate theo recovery-safe contract.",
  "roles": [
    "public"
  ],
  "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-pair-redeem-0",
          "child-pair-redeem-1",
          "child-pair-redeem-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": "public unpaired",
        "backTarget": null,
        "settingsTarget": null
      },
      "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-pair-redeem-0",
      "type": "Field",
      "props": {
        "name": "pairing_code",
        "label": "Mã ghép 6 chữ số",
        "type": "text",
        "value": "",
        "required": true,
        "min": null,
        "max": null,
        "options": null,
        "hint": "Mã thử: 472816. Không nhập mã thật.",
        "pattern": "[0-9 ]{6,7}"
      },
      "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": "Mã ghép 6 chữ số",
        "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-pair-redeem-1",
      "type": "Field",
      "props": {
        "name": "device_label",
        "label": "Tên thiết bị",
        "type": "text",
        "value": "Máy của Bông",
        "required": true,
        "min": null,
        "max": null,
        "options": null,
        "hint": null,
        "pattern": null
      },
      "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": "Tên thiết bị",
        "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-pair-redeem-2",
      "type": "Notice",
      "props": {
        "text": "Chỉ ghép khi có phụ huynh bên cạnh. Bản mẫu không cấp quyền truy cập 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": "Nhập mã của phụ huynh · Notice",
        "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": "Ghép thiết bị mẫu",
            "kind": "submit",
            "target": "child-today",
            "confirmationRequired": false
          },
          {
            "id": "navigate-1",
            "label": "Nhờ phụ huynh cấp mã mới",
            "kind": "navigate",
            "target": "entry-mode",
            "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": [
    {
      "id": "pairing_code",
      "label": "Mã ghép 6 chữ số",
      "control": "text",
      "default": "",
      "options": null,
      "validation": {
        "required": true,
        "trim": true,
        "type": "text",
        "min": null,
        "max": null,
        "pattern": "[0-9 ]{6,7}",
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra mã ghép 6 chữ số."
      },
      "binding": "pairing_code",
      "keyboard": "text",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    },
    {
      "id": "device_label",
      "label": "Tên thiết bị",
      "control": "text",
      "default": "Máy của Bông",
      "options": null,
      "validation": {
        "required": true,
        "trim": true,
        "type": "text",
        "min": null,
        "max": null,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra tên thiết bị."
      },
      "binding": "device_label",
      "keyboard": "text",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    }
  ],
  "states": [
    {
      "id": "unpaired",
      "when": "Không credential",
      "visibleUI": "Chỉ nhập proof/device metadata",
      "availableActions": [
        "navigate-0",
        "navigate-1"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "invalid",
      "when": "Proof sai/đã dùng/hết hạn",
      "visibleUI": "Không lộ child identity",
      "availableActions": [
        "navigate-0",
        "navigate-1"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "prepared",
      "when": "Redeem accepted",
      "visibleUI": "Lưu credential SecureStore trước activate",
      "availableActions": [
        "navigate-0",
        "navigate-1"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "active",
      "when": "Activate ack hoặc canonical recovery",
      "visibleUI": "Mới mở child scope",
      "availableActions": [
        "navigate-0",
        "navigate-1"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "navigate-0",
      "label": "Ghép thiết bị mẫu",
      "kind": "submit",
      "targetScreenId": "child-today",
      "permission": "public unpaired",
      "confirmationRequired": false,
      "contractRef": "local draft/navigation",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": null
    },
    {
      "id": "navigate-1",
      "label": "Nhờ phụ huynh cấp mã mới",
      "kind": "navigate",
      "targetScreenId": "entry-mode",
      "permission": "public unpaired",
      "confirmationRequired": false,
      "contractRef": "local draft/navigation",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": null
    }
  ],
  "dataBindings": [
    {
      "source": "POST /v1/child-pairings/redeem",
      "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": "Nhập mã của phụ huynh",
    "primary": "Ghép thiết bị mẫu",
    "empty": null,
    "notices": [
      "Chỉ ghép khi có phụ huynh bên cạnh. Bản mẫu không cấp quyền truy cập 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-pair-redeem",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [
      "POST /v1/child-pairings/redeem",
      "POST /v1/child-pairings/{redemption_id}/activate"
    ],
    "newContractRefs": [],
    "notes": [
      "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": "public unpaired",
    "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."
    }
  }
}
