{
  "schemaVersion": "1.0",
  "id": "data-export",
  "title": "Xuất dữ liệu của tôi",
  "purpose": "Scoped export job and private authorized download, no public URL.",
  "roles": [
    "adult"
  ],
  "group": "settings-privacy",
  "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 export",
        "componentIds": [
          "screen-header",
          "data-export-0",
          "data-export-1",
          "data-export-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",
        "backTarget": "privacy",
        "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": "data-export-0",
      "type": "ChoiceGroup",
      "props": {
        "legend": "Phạm vi",
        "name": "scope",
        "options": [
          [
            "own",
            "Dữ liệu và lịch sử của tôi"
          ],
          [
            "child",
            "Dữ liệu Bông · cần G và chính sách cho phép"
          ]
        ],
        "multiple": false
      },
      "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": "Xuất dữ liệu của tôi · ChoiceGroup",
        "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": "data-export-1",
      "type": "DetailList",
      "props": {
        "items": [
          [
            "Định dạng dự kiến",
            "JSON/CSV theo cấu hình"
          ],
          [
            "Trạng thái mẫu",
            "Chưa yêu cầu"
          ],
          [
            "Bảo vệ",
            "Tải riêng sau kiểm quyề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": "Xuất dữ liệu của tôi · DetailList",
        "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": "data-export-2",
      "type": "Notice",
      "props": {
        "text": "Bản mẫu không xuất dữ liệu thật. Công việc lớn có trạng thái chờ/ready/failed/expired.",
        "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": "Xuất dữ liệu của tôi · 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": "export",
            "label": "Xem yêu cầu xuất mẫu",
            "kind": "mutate",
            "target": null,
            "confirmationRequired": true
          },
          {
            "id": "link-privacy",
            "label": "Dữ liệu của bạn",
            "kind": "navigate",
            "target": "privacy",
            "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": [
    {
      "id": "scope",
      "label": "Phạm vi",
      "control": "radio",
      "options": [
        {
          "value": "own",
          "label": "Dữ liệu và lịch sử của tôi"
        },
        {
          "value": "child",
          "label": "Dữ liệu Bông · cần G và chính sách cho phép"
        }
      ],
      "validation": {
        "required": true,
        "allowlist": [
          "own",
          "child"
        ],
        "minSelections": 1,
        "errorMessage": "Chọn ít nhất một mục phù hợp."
      },
      "binding": "scope",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    }
  ],
  "states": [
    {
      "id": "pending",
      "when": "Job requested",
      "visibleUI": "Polling own job id",
      "availableActions": [
        "link-privacy",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "ready",
      "when": "Scope/epoch still allowed",
      "visibleUI": "Authorized streamed download",
      "availableActions": [
        "export",
        "link-privacy",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "expired",
      "when": "Artifact expired",
      "visibleUI": "Request new export",
      "availableActions": [
        "link-privacy",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "revoked",
      "when": "Lost scope",
      "visibleUI": "Do not expose private object URL",
      "availableActions": [
        "link-privacy",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "export",
      "label": "Xem yêu cầu xuất mẫu",
      "kind": "mutate",
      "targetScreenId": null,
      "permission": "U own; G child policy",
      "confirmationRequired": true,
      "contractRef": "POST /v1/account/export",
      "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-privacy",
      "label": "Dữ liệu của bạn",
      "kind": "navigate",
      "targetScreenId": "privacy",
      "permission": "A",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-settings",
      "label": "Cài đặt",
      "kind": "navigate",
      "targetScreenId": "settings",
      "permission": "A",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    }
  ],
  "dataBindings": [
    {
      "source": "POST /v1/account/export",
      "shape": {
        "export_job_id": "opaque ID",
        "state": "queued|building|ready|failed|expired|revoked",
        "generation": "integer",
        "requested_at": "UTC",
        "expires_at": "UTC",
        "failure_code": "string|null"
      },
      "sample": {
        "export_job_id": "export-example",
        "state": "queued",
        "generation": 1,
        "requested_at": "2026-10-14T05:00:00Z",
        "expires_at": "2026-10-15T05:00:00Z",
        "failure_code": null
      },
      "sampleOnly": true,
      "actorConstraint": "exact actor allowlist",
      "envelope": "API refs use CommandEnvelope; local review context is not an API property."
    }
  ],
  "copy": {
    "heading": "Xuất dữ liệu của tôi",
    "primary": "Xem yêu cầu xuất mẫu",
    "empty": null,
    "notices": [
      "Bản mẫu không xuất dữ liệu thật. Công việc lớn có trạng thái chờ/ready/failed/expired."
    ],
    "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/data-export",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [
      "POST /v1/account/export",
      "GET /v1/account/exports/{id}",
      "GET /v1/account/exports/{id}/download"
    ],
    "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": "A",
    "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."
    }
  }
}
