{
  "schemaVersion": "1.0",
  "id": "account-deletion",
  "title": "Xem trước khi xóa",
  "purpose": "Deletion policy/reauth/dependencies and explicit irreversible confirmation.",
  "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 deletion",
        "componentIds": [
          "screen-header",
          "account-deletion-0",
          "account-deletion-1",
          "account-deletion-2",
          "account-deletion-3",
          "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": "U reauth + policy",
        "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": "account-deletion-0",
      "type": "DeleteReview",
      "props": {
        "contentText": "Tài khoản và dữ liệu riêng  Phải xem chính sách đã duyệt để biết dữ liệu nào bị xóa, được ẩn hay cần giữ theo quy định.  Không có yêu cầu xóa thật trong bản mẫu này."
      },
      "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": "Xem trước khi xóa · DeleteReview",
        "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": "account-deletion-1",
      "type": "SettingsGroup",
      "props": {
        "items": [
          {
            "label": "Xử lý quyền chủ nhà và guardian",
            "description": "Giải quyết trước khi yêu cầu",
            "target": "leave-household"
          },
          {
            "label": "Lấy bản sao dữ liệu",
            "description": "Không cần Pro",
            "target": "data-export"
          }
        ]
      },
      "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": "Xem trước khi xóa · SettingsGroup",
        "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": "account-deletion-2",
      "type": "Field",
      "props": {
        "name": "confirm_text",
        "label": "Nhập XÓA để xem bước xác nhận",
        "type": "text",
        "value": "",
        "required": true,
        "min": null,
        "max": null,
        "options": null,
        "hint": null,
        "pattern": "XÓA"
      },
      "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 XÓA để xem bước xác nhận",
        "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": "account-deletion-3",
      "type": "Notice",
      "props": {
        "text": "Cần xác minh lại danh tính. Nếu chưa có chính sách/xóa chưa bật, không nhận yêu cầu.",
        "tone": "warn"
      },
      "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": "Xem trước khi xóa · Notice",
        "readingOrder": 4,
        "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": "delete-account",
            "label": "Xem bước yêu cầu xóa",
            "kind": "mutate",
            "target": "deletion-progress",
            "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
          },
          {
            "id": "link-leave-household",
            "label": "Rời Nhà Lá",
            "kind": "navigate",
            "target": "leave-household",
            "confirmationRequired": false
          },
          {
            "id": "link-data-export",
            "label": "Xuất dữ liệu của tôi",
            "kind": "navigate",
            "target": "data-export",
            "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": "confirm_text",
      "label": "Nhập XÓA để xem bước xác nhận",
      "control": "text",
      "default": "",
      "options": null,
      "validation": {
        "required": true,
        "trim": true,
        "type": "text",
        "min": null,
        "max": null,
        "pattern": "XÓA",
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra nhập xóa để xem bước xác nhận."
      },
      "binding": "confirm_text",
      "keyboard": "text",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    }
  ],
  "states": [
    {
      "id": "policy-blocked",
      "when": "deletion_enabled false or missing",
      "visibleUI": "No accepted request",
      "availableActions": [
        "link-privacy",
        "link-settings",
        "link-leave-household",
        "link-data-export"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "dependencies",
      "when": "Owner/last guardian",
      "visibleUI": "Show specific dependency steps",
      "availableActions": [
        "delete-account",
        "link-privacy",
        "link-settings",
        "link-leave-household",
        "link-data-export"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "reauth",
      "when": "Identity not fresh",
      "visibleUI": "Native reauth before submit",
      "availableActions": [
        "delete-account",
        "link-privacy",
        "link-settings",
        "link-leave-household",
        "link-data-export"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "preparing",
      "when": "Write-ahead intent pending",
      "visibleUI": "Stable command/status capability",
      "availableActions": [
        "delete-account",
        "link-privacy",
        "link-settings",
        "link-leave-household",
        "link-data-export"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "delete-account",
      "label": "Xem bước yêu cầu xóa",
      "kind": "mutate",
      "targetScreenId": "deletion-progress",
      "permission": "U reauth + policy enabled",
      "confirmationRequired": true,
      "contractRef": "POST /v1/account/deletion-request",
      "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": "U reauth + policy",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-settings",
      "label": "Cài đặt",
      "kind": "navigate",
      "targetScreenId": "settings",
      "permission": "U reauth + policy",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-leave-household",
      "label": "Rời Nhà Lá",
      "kind": "navigate",
      "targetScreenId": "leave-household",
      "permission": "U reauth + policy",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-data-export",
      "label": "Xuất dữ liệu của tôi",
      "kind": "navigate",
      "targetScreenId": "data-export",
      "permission": "U reauth + policy",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    }
  ],
  "dataBindings": [
    {
      "source": "GET /v1/account/data-policy",
      "shape": {
        "deletion_request_id": "opaque ID",
        "state": "awaiting_transfer|preparing_recovery_intent|accepted|processing|completed|blocked",
        "dependency_code": "string|null",
        "requested_at": "UTC",
        "accepted_at": "UTC|null",
        "completed_at": "UTC|null"
      },
      "sample": {
        "deletion_request_id": "delete-example",
        "state": "awaiting_transfer",
        "dependency_code": "OWNER_REQUIRED",
        "requested_at": "2026-10-14T05:00:00Z",
        "accepted_at": null,
        "completed_at": null
      },
      "sampleOnly": true,
      "actorConstraint": "exact actor allowlist",
      "envelope": "API refs use CommandEnvelope; local review context is not an API property."
    }
  ],
  "copy": {
    "heading": "Xem trước khi xóa",
    "primary": "Xem bước yêu cầu xóa",
    "empty": null,
    "notices": [
      "Cần xác minh lại danh tính. Nếu chưa có chính sách/xóa chưa bật, không nhận yêu cầu."
    ],
    "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/account-deletion",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [
      "GET /v1/account/data-policy",
      "POST /v1/account/deletion-request"
    ],
    "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": "U reauth + policy",
    "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."
    }
  }
}
