{
  "schemaVersion": "1.0",
  "id": "microphone-permission",
  "title": "Nói thay vì gõ",
  "purpose": "Microphone app rationale and denied recovery with typed input always available.",
  "roles": [
    "adult",
    "child"
  ],
  "group": "ai-assistant",
  "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 permission",
        "componentIds": [
          "screen-header",
          "microphone-permission-0",
          "microphone-permission-1",
          "microphone-permission-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": "A/C OS microphone consent",
        "backTarget": "ai-chat",
        "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": "microphone-permission-0",
      "type": "MicrophoneRationale",
      "props": {
        "contentText": "Đọc việc bạn muốn ghi  Sau khi nói, bạn sửa bản chép trước khi gửi. Không có thay đổi nào được lưu tự động."
      },
      "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": "Nói thay vì gõ · MicrophoneRationale",
        "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": "microphone-permission-1",
      "type": "Notice",
      "props": {
        "text": "Bản mẫu không xin quyền hoặc thu âm thật. Ứng dụng native dùng màn quyền do iOS/Android quản lý.",
        "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": "Nói thay vì gõ · 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": "microphone-permission-2",
      "type": "MicrophoneDenied",
      "props": {
        "contentText": "Micro đã bị từ chối?  Vào Cài đặt thiết bị → Chia Việc → Micro. Bạn cũng có thể nhập tin nhắn bằng tay ngay."
      },
      "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": "Nói thay vì gõ · MicrophoneDenied",
        "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": "Thử giọng nói dựng sẵn",
            "kind": "navigate",
            "target": "ai-listening",
            "confirmationRequired": false
          },
          {
            "id": "navigate-1",
            "label": "Nhập bằng bàn phím",
            "kind": "navigate",
            "target": "ai-chat",
            "confirmationRequired": false
          },
          {
            "id": "link-settings",
            "label": "Cài đặt",
            "kind": "navigate",
            "target": "settings",
            "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": "rationale",
      "when": "Permission notDetermined",
      "visibleUI": "Explain before native request",
      "availableActions": [
        "navigate-0",
        "navigate-1",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "denied",
      "when": "Permission denied/restricted",
      "visibleUI": "Device settings recovery and text path",
      "availableActions": [
        "navigate-0",
        "navigate-1",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "granted",
      "when": "OS callback granted",
      "visibleUI": "User starts recording; not automatic",
      "availableActions": [
        "navigate-0",
        "navigate-1",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "navigate-0",
      "label": "Thử giọng nói dựng sẵn",
      "kind": "navigate",
      "targetScreenId": "ai-listening",
      "permission": "A/C OS microphone consent",
      "confirmationRequired": false,
      "contractRef": "local navigation",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": null
    },
    {
      "id": "navigate-1",
      "label": "Nhập bằng bàn phím",
      "kind": "navigate",
      "targetScreenId": "ai-chat",
      "permission": "A/C OS microphone consent",
      "confirmationRequired": false,
      "contractRef": "local navigation",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": null
    },
    {
      "id": "link-settings",
      "label": "Cài đặt",
      "kind": "navigate",
      "targetScreenId": "settings",
      "permission": "A/C OS microphone consent",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    }
  ],
  "dataBindings": [
    {
      "source": "localized local design scenario / proposed assistant adapter",
      "shape": {
        "os_state": "notDetermined|granted|denied|restricted",
        "app_opt_in": "boolean",
        "native_adapter": "not integrated"
      },
      "sample": {
        "os_state": "notDetermined",
        "app_opt_in": false,
        "native_adapter": "not integrated"
      },
      "sampleOnly": true,
      "actorConstraint": "Adult example only; child requests MUST bind ChildTodayDto/ChildHistoryDto/ChildOccurrenceDto own scope; no adult IDs/contact/roster",
      "envelope": "API refs use CommandEnvelope; local review context is not an API property."
    }
  ],
  "copy": {
    "heading": "Nói thay vì gõ",
    "primary": "Thử giọng nói dựng sẵn",
    "empty": null,
    "notices": [
      "Bản mẫu không xin quyền hoặc thu âm thật. Ứng dụng native dùng màn quyền do iOS/Android quản lý."
    ],
    "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/microphone-permission",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [],
    "newContractRefs": [
      "ai-agent-contract.json"
    ],
    "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": "A/C OS microphone consent",
    "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."
    }
  }
}
