{
  "schemaVersion": "1.0",
  "id": "task-create",
  "title": "Thêm một việc",
  "purpose": "Biểu mẫu việc với room, effort, lặp, due và nhóm phân công hợp lệ.",
  "roles": [
    "adult"
  ],
  "group": "chores-spaces",
  "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 task",
        "componentIds": [
          "screen-header",
          "task-create-0",
          "task-create-1",
          "task-create-2",
          "task-create-3",
          "task-create-4",
          "task-create-5",
          "task-create-6",
          "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",
        "backTarget": "today",
        "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": "task-create-0",
      "type": "Field",
      "props": {
        "name": "title",
        "label": "Tên việc",
        "type": "text",
        "value": "",
        "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": 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": "task-create-1",
      "type": "Field",
      "props": {
        "name": "room_id",
        "label": "Không gian",
        "type": "select",
        "value": "kitchen",
        "required": true,
        "min": null,
        "max": null,
        "options": [
          [
            "kitchen",
            "Bếp chung"
          ],
          [
            "living",
            "Phòng khách"
          ]
        ],
        "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": "Không gian",
        "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": "task-create-2",
      "type": "Field",
      "props": {
        "name": "effort",
        "label": "Công sức",
        "type": "select",
        "value": 2,
        "required": true,
        "min": null,
        "max": null,
        "options": [
          [
            "1",
            "1 · Nhẹ"
          ],
          [
            "2",
            "2 · Vừa"
          ],
          [
            "3",
            "3 · Nhiều"
          ]
        ],
        "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": 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": "task-create-3",
      "type": "Field",
      "props": {
        "name": "instructions",
        "label": "Hướng dẫn",
        "type": "textarea",
        "value": "Rửa bát, để ráo và cất đúng chỗ.",
        "required": false,
        "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": "Hướng dẫn",
        "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": "task-create-4",
      "type": "SettingsGroup",
      "props": {
        "items": [
          {
            "label": "Lịch lặp",
            "description": "Mỗi ngày · từ 14/10/2026",
            "target": "task-recurrence"
          },
          {
            "label": "Người phụ trách",
            "description": "Cố định · An",
            "target": "task-assignment"
          }
        ]
      },
      "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": "Thêm một việc · SettingsGroup",
        "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": "task-create-5",
      "type": "Field",
      "props": {
        "name": "first_due_local_date",
        "label": "Ngày đến hạn đầu",
        "type": "date",
        "value": "2026-10-14",
        "required": true,
        "min": null,
        "max": null,
        "options": null,
        "hint": "Sửa template chỉ ảnh hưởng kỳ sau; không đổi snapshot kỳ đang mở.",
        "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": "Ngày đến hạn đầu",
        "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": "task-create-6",
      "type": "Notice",
      "props": {
        "text": "Trẻ chỉ được chọn khi đã có xác nhận đủ điều kiện cho chính việc nà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": "Thêm một việc · Notice",
        "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": "screen-actions",
      "type": "ActionGroup",
      "props": {
        "actions": [
          {
            "id": "save-task",
            "label": "Lưu việc trên máy",
            "kind": "mutate",
            "target": "task-detail",
            "confirmationRequired": false
          },
          {
            "id": "navigate-1",
            "label": "Nhờ AI soạn giúp",
            "kind": "navigate",
            "target": "ai-chat",
            "confirmationRequired": false
          },
          {
            "id": "link-today",
            "label": "Hôm nay",
            "kind": "navigate",
            "target": "today",
            "confirmationRequired": false
          },
          {
            "id": "link-settings",
            "label": "Cài đặt",
            "kind": "navigate",
            "target": "settings",
            "confirmationRequired": false
          },
          {
            "id": "link-task-recurrence",
            "label": "Nhịp lặp phù hợp",
            "kind": "navigate",
            "target": "task-recurrence",
            "confirmationRequired": false
          },
          {
            "id": "link-task-assignment",
            "label": "Ai phụ trách việc này?",
            "kind": "navigate",
            "target": "task-assignment",
            "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": "",
      "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": "room_id",
      "label": "Không gian",
      "control": "select",
      "default": "kitchen",
      "options": [
        [
          "kitchen",
          "Bếp chung"
        ],
        [
          "living",
          "Phòng khách"
        ]
      ],
      "validation": {
        "required": true,
        "trim": false,
        "type": "select",
        "min": null,
        "max": null,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra không gian."
      },
      "binding": "room_id",
      "keyboard": "select",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    },
    {
      "id": "effort",
      "label": "Công sức",
      "control": "select",
      "default": 2,
      "options": [
        [
          "1",
          "1 · Nhẹ"
        ],
        [
          "2",
          "2 · Vừa"
        ],
        [
          "3",
          "3 · Nhiều"
        ]
      ],
      "validation": {
        "required": true,
        "trim": false,
        "type": "select",
        "min": null,
        "max": null,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra công sức."
      },
      "binding": "effort",
      "keyboard": "select",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    },
    {
      "id": "instructions",
      "label": "Hướng dẫn",
      "control": "textarea",
      "default": "Rửa bát, để ráo và cất đúng chỗ.",
      "options": null,
      "validation": {
        "required": false,
        "trim": true,
        "type": "textarea",
        "min": null,
        "max": null,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra hướng dẫn."
      },
      "binding": "instructions",
      "keyboard": "textarea",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    },
    {
      "id": "first_due_local_date",
      "label": "Ngày đến hạn đầu",
      "control": "date",
      "default": "2026-10-14",
      "options": null,
      "validation": {
        "required": true,
        "trim": false,
        "type": "date",
        "min": null,
        "max": null,
        "pattern": null,
        "serverAuthoritative": true,
        "errorMessage": "Kiểm tra ngày đến hạn đầu."
      },
      "binding": "first_due_local_date",
      "keyboard": "date",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    }
  ],
  "states": [
    {
      "id": "editing",
      "when": "Draft hợp lệ",
      "visibleUI": "Hiển thị tất cả trường bắt buộc",
      "availableActions": [
        "save-task",
        "navigate-1",
        "link-today",
        "link-settings",
        "link-task-recurrence",
        "link-task-assignment"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "invalid",
      "when": "422 VALIDATION_FAILED",
      "visibleUI": "Tên, room, effort và due được kiểm tra",
      "availableActions": [
        "save-task",
        "navigate-1",
        "link-today",
        "link-settings",
        "link-task-recurrence",
        "link-task-assignment"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "offline",
      "when": "Không có kết nối",
      "visibleUI": "Giữ draft; không giả backend save",
      "availableActions": [
        "navigate-1",
        "link-today",
        "link-settings",
        "link-task-recurrence",
        "link-task-assignment"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "conflict",
      "when": "Version template thay đổi",
      "visibleUI": "Không tự ghi đè",
      "availableActions": [
        "navigate-1",
        "link-today",
        "link-settings",
        "link-task-recurrence",
        "link-task-assignment"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "save-task",
      "label": "Lưu việc trên máy",
      "kind": "mutate",
      "targetScreenId": "task-detail",
      "permission": "E",
      "confirmationRequired": false,
      "contractRef": "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": "Nhờ AI soạn giúp",
      "kind": "navigate",
      "targetScreenId": "ai-chat",
      "permission": "E",
      "confirmationRequired": false,
      "contractRef": "local draft/navigation",
      "localBehavior": "Only validated draft/local domain where supported; remote adapters never report success.",
      "idempotency": null
    },
    {
      "id": "link-today",
      "label": "Hôm nay",
      "kind": "navigate",
      "targetScreenId": "today",
      "permission": "E",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-settings",
      "label": "Cài đặt",
      "kind": "navigate",
      "targetScreenId": "settings",
      "permission": "E",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-task-recurrence",
      "label": "Nhịp lặp phù hợp",
      "kind": "navigate",
      "targetScreenId": "task-recurrence",
      "permission": "E",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-task-assignment",
      "label": "Ai phụ trách việc này?",
      "kind": "navigate",
      "targetScreenId": "task-assignment",
      "permission": "E",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    }
  ],
  "dataBindings": [
    {
      "source": "POST /v1/households/{hid}/tasks",
      "shape": {
        "task_id": "opaque ID",
        "room_id": "same-home ID",
        "title": "string",
        "effort": "1|2|3",
        "recurrence": "{kind:interval,intervalDays:integer}|{kind:weekdays,weekdays:1..7[]}",
        "anchor_local_date": "date",
        "assignment_mode": "fixed|round_robin|auto",
        "eligible_member_ids": "same-home active ID[]",
        "version": "integer"
      },
      "sample": {
        "task_id": "dishes",
        "room_id": "kitchen",
        "title": "Rửa bát sau bữa tối",
        "effort": 2,
        "recurrence": {
          "kind": "interval",
          "intervalDays": 1
        },
        "anchor_local_date": "2026-10-14",
        "assignment_mode": "fixed",
        "eligible_member_ids": [
          "an"
        ],
        "version": 1
      },
      "sampleOnly": true,
      "actorConstraint": "exact actor allowlist",
      "envelope": "API refs use CommandEnvelope; local review context is not an API property."
    }
  ],
  "copy": {
    "heading": "Thêm một việc",
    "primary": "Lưu việc trên máy",
    "empty": null,
    "notices": [
      "Trẻ chỉ được chọn khi đã có xác nhận đủ điều kiện cho chính việc này."
    ],
    "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/task-create",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [
      "POST /v1/households/{hid}/tasks",
      "PATCH /v1/households/{hid}/tasks/{tid}"
    ],
    "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.",
      "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",
    "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."
    }
  }
}
