{
  "schemaVersion": "1.0",
  "id": "ai-proposal",
  "title": "Xem trước thay đổi",
  "purpose": "Exact editable proposal recipient/due/recurrence/effort/conflicts before confirm.",
  "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 proposal",
        "componentIds": [
          "screen-header",
          "ai-proposal-0",
          "ai-proposal-1",
          "ai-proposal-2",
          "ai-proposal-3",
          "ai-proposal-4",
          "ai-proposal-5",
          "ai-proposal-6",
          "ai-proposal-7",
          "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": "E bound actor/household",
        "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": "ai-proposal-0",
      "type": "Notice",
      "props": {
        "text": "Đề xuất mẫu · chưa lưu việc. Chỉ xác nhận bên dưới mới áp dụng trên máy.",
        "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": "Xem trước thay đổi · Notice",
        "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": "ai-proposal-1",
      "type": "ProposalDiff",
      "props": {
        "contentText": "Tạo việc mới  Trước: chưa có việc Lau mặt bếp mỗi 2 ngày  Sau: Bếp chung · An · công sức 1"
      },
      "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 thay đổi · ProposalDiff",
        "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": "ai-proposal-2",
      "type": "Field",
      "props": {
        "name": "title",
        "label": "Tên việc",
        "type": "text",
        "value": "Lau mặt bếp",
        "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 việc",
        "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": "ai-proposal-3",
      "type": "Field",
      "props": {
        "name": "effort",
        "label": "Công sức",
        "type": "number",
        "value": 1,
        "required": true,
        "min": 1,
        "max": 3,
        "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": "Công sức",
        "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": "ai-proposal-4",
      "type": "Field",
      "props": {
        "name": "first_due_local_date",
        "label": "Đến hạn đầu",
        "type": "date",
        "value": "2026-10-15",
        "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": "Đến hạn đầu",
        "readingOrder": 5,
        "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": "ai-proposal-5",
      "type": "Field",
      "props": {
        "name": "intervalDays",
        "label": "Lặp mỗi (ngày)",
        "type": "number",
        "value": 2,
        "required": true,
        "min": 1,
        "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": "Lặp mỗi (ngày)",
        "readingOrder": 6,
        "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": "ai-proposal-6",
      "type": "DetailList",
      "props": {
        "items": [
          [
            "Người nhận",
            "An · member ID trong Nhà Lá"
          ],
          [
            "Phân công",
            "Cố định"
          ],
          [
            "Quyền",
            "Người lớn active có quyền sửa/chia việc"
          ],
          [
            "Xung đột",
            "Không có ở dữ liệu mẫu hiện tại"
          ]
        ]
      },
      "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 thay đổi · DetailList",
        "readingOrder": 7,
        "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": "ai-proposal-7",
      "type": "Notice",
      "props": {
        "text": "Nếu dữ liệu hoặc quyền thay đổi, đề xuất hết hiệu lực và cần bạn xác nhận lại.",
        "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 thay đổi · Notice",
        "readingOrder": 8,
        "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": "confirm-proposal",
            "label": "Xác nhận áp dụng trên máy",
            "kind": "mutate",
            "target": "ai-action-result",
            "confirmationRequired": true
          },
          {
            "id": "navigate-1",
            "label": "Hủy đề xuất",
            "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": [
    {
      "id": "title",
      "label": "Tên việc",
      "control": "text",
      "default": "Lau mặt bếp",
      "options": null,
      "validation": {
        "required": true,
        "trim": true,
        "type": "text",
        "min": null,
        "max": null,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra tên việc.",
        "nonBlank": true
      },
      "binding": "title",
      "keyboard": "text",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    },
    {
      "id": "effort",
      "label": "Công sức",
      "control": "number",
      "default": 1,
      "options": null,
      "validation": {
        "required": true,
        "trim": false,
        "type": "number",
        "min": 1,
        "max": 3,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra công sức."
      },
      "binding": "effort",
      "keyboard": "numeric",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    },
    {
      "id": "first_due_local_date",
      "label": "Đến hạn đầu",
      "control": "date",
      "default": "2026-10-15",
      "options": null,
      "validation": {
        "required": true,
        "trim": false,
        "type": "date",
        "min": null,
        "max": null,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra đến hạn đầu."
      },
      "binding": "first_due_local_date",
      "keyboard": "date",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    },
    {
      "id": "intervalDays",
      "label": "Lặp mỗi (ngày)",
      "control": "number",
      "default": 2,
      "options": null,
      "validation": {
        "required": true,
        "trim": false,
        "type": "number",
        "min": 1,
        "max": null,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra lặp mỗi (ngày)."
      },
      "binding": "intervalDays",
      "keyboard": "numeric",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    }
  ],
  "states": [
    {
      "id": "review",
      "when": "Validated proposal unchanged",
      "visibleUI": "Editable fields invalidate former confirmation",
      "availableActions": [
        "confirm-proposal",
        "navigate-1",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "confirmed",
      "when": "Explicit user confirm current draft",
      "visibleUI": "Command key frozen per action",
      "availableActions": [
        "confirm-proposal",
        "navigate-1",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "stale",
      "when": "Revision/entity/grant version changed",
      "visibleUI": "No write, pull + regenerate + reconfirm",
      "availableActions": [
        "navigate-1",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "forbidden",
      "when": "Actor/scope changed",
      "visibleUI": "Reject, no grant escalation",
      "availableActions": [
        "navigate-1",
        "link-settings"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "confirm-proposal",
      "label": "Xác nhận áp dụng trên máy",
      "kind": "mutate",
      "targetScreenId": "ai-action-result",
      "permission": "E bound actor + household + revisions",
      "confirmationRequired": true,
      "contractRef": "PROPOSED ai.confirm → POST /v1/households/{hid}/tasks",
      "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": "navigate-1",
      "label": "Hủy đề xuất",
      "kind": "navigate",
      "targetScreenId": "ai-chat",
      "permission": "E bound actor/household",
      "confirmationRequired": false,
      "contractRef": "local draft/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": "E bound actor/household",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    }
  ],
  "dataBindings": [
    {
      "source": "POST /v1/households/{hid}/tasks",
      "shape": {
        "proposal_id": "opaque ID",
        "actor_id": "bound ID",
        "household_id": "bound ID",
        "household_revision": "integer",
        "entity_versions": "map",
        "confirmation": "explicit draft hash + confirmed_by",
        "commands": "allowlisted version/idempotency inputs"
      },
      "sample": {
        "proposal_id": "proposal-example",
        "actor_id": "an",
        "household_id": "home-leaf",
        "household_revision": 1,
        "entity_versions": {},
        "confirmation": null,
        "commands": [
          {
            "kind": "create_task",
            "title": "Lau mặt bếp",
            "room_id": "kitchen",
            "effort": 1,
            "recurrence": {
              "kind": "interval",
              "intervalDays": 2
            },
            "first_due_local_date": "2026-10-15",
            "assignment_mode": "fixed",
            "fixed_assignee_member_id": "an",
            "eligible_member_ids": [
              "an"
            ]
          }
        ]
      },
      "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": "Xem trước thay đổi",
    "primary": "Xác nhận áp dụng trên máy",
    "empty": null,
    "notices": [
      "Đề xuất mẫu · chưa lưu việc. Chỉ xác nhận bên dưới mới áp dụng trên máy.",
      "Nếu dữ liệu hoặc quyền thay đổi, đề xuất hết hiệu lực và cần bạn xác nhận lại."
    ],
    "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/ai-proposal",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [
      "POST /v1/households/{hid}/tasks"
    ],
    "newContractRefs": [
      "ai-agent-contract.json"
    ],
    "notes": [
      "No prose eval/DB writes. Existing validation/version/idempotency endpoints only. Proposed ai-agent-contract separate.",
      "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.",
      "Accepted-day recurrence; occurrence due/effort snapshot bất biến; snooze không đổi anchor; pending không reassign; undo điều chỉnh ledger đúng một lần."
    ],
    "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": "E bound actor/household",
    "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."
    }
  }
}
