{
  "schemaVersion": "1.0",
  "id": "task-assignment",
  "title": "Ai phụ trách việc này?",
  "purpose": "Giao cố định hoặc round_robin cùng-home stable member IDs.",
  "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-assignment-0",
          "task-assignment-1",
          "task-assignment-2",
          "task-assignment-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": "E",
        "backTarget": "task-create",
        "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-assignment-0",
      "type": "ChoiceGroup",
      "props": {
        "legend": "Cách chia",
        "name": "assignment_mode",
        "options": [
          [
            "fixed",
            "Cố định · một người"
          ],
          [
            "round_robin",
            "Luân phiên · nhóm đủ điều kiện"
          ]
        ],
        "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": "Ai phụ trách việc này? · 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": "task-assignment-1",
      "type": "ChoiceGroup",
      "props": {
        "legend": "Nhóm được chọn",
        "name": "eligible_member_ids",
        "options": [
          [
            "an",
            "An · người lớn"
          ],
          [
            "minh",
            "Minh · người lớn"
          ]
        ],
        "multiple": true
      },
      "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": "Ai phụ trách việc này? · ChoiceGroup",
        "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-assignment-2",
      "type": "Notice",
      "props": {
        "text": "Bông chưa được phụ huynh cho phép làm việc này. Quyền chủ nhà không thay cho xác nhận đó.",
        "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": "Ai phụ trách việc này? · 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": "task-assignment-3",
      "type": "SettingsGroup",
      "props": {
        "items": [
          {
            "label": "Xác nhận việc cho trẻ",
            "description": "Chỉ guardian của Bông được thực hiện",
            "target": "child-profile-detail"
          }
        ]
      },
      "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": "Ai phụ trách việc này? · SettingsGroup",
        "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": "navigate-0",
            "label": "Giữ phân công trong bản nháp",
            "kind": "submit",
            "target": "task-create",
            "confirmationRequired": false
          },
          {
            "id": "link-settings",
            "label": "Cài đặt",
            "kind": "navigate",
            "target": "settings",
            "confirmationRequired": false
          },
          {
            "id": "link-child-profile-detail",
            "label": "Bông",
            "kind": "navigate",
            "target": "child-profile-detail",
            "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": "assignment_mode",
      "label": "Cách chia",
      "control": "radio",
      "options": [
        {
          "value": "fixed",
          "label": "Cố định · một người"
        },
        {
          "value": "round_robin",
          "label": "Luân phiên · nhóm đủ điều kiện"
        }
      ],
      "validation": {
        "required": true,
        "allowlist": [
          "fixed",
          "round_robin"
        ],
        "minSelections": 1,
        "errorMessage": "Chọn ít nhất một mục phù hợp."
      },
      "binding": "assignment_mode",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    },
    {
      "id": "eligible_member_ids",
      "label": "Nhóm được chọn",
      "control": "checkbox",
      "options": [
        {
          "value": "an",
          "label": "An · người lớn"
        },
        {
          "value": "minh",
          "label": "Minh · người lớn"
        }
      ],
      "validation": {
        "required": true,
        "allowlist": [
          "an",
          "minh"
        ],
        "minSelections": 1,
        "errorMessage": "Chọn ít nhất một mục phù hợp.",
        "exactSelectionsWhenFixed": 1
      },
      "binding": "eligible_member_ids",
      "accessibleErrorAssociation": "form error summary via role alert; native bind field-specific error ID"
    }
  ],
  "states": [
    {
      "id": "fixed",
      "when": "mode=fixed",
      "visibleUI": "Một assignee phải thuộc eligible IDs",
      "availableActions": [
        "navigate-0",
        "link-settings",
        "link-child-profile-detail"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "rotation",
      "when": "mode=round_robin",
      "visibleUI": "Nhóm active, không rỗng",
      "availableActions": [
        "navigate-0",
        "link-settings",
        "link-child-profile-detail"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "pending-submission",
      "when": "Occurrence đang chờ duyệt",
      "visibleUI": "Không chuyển người kỳ này",
      "availableActions": [
        "link-settings",
        "link-child-profile-detail"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    },
    {
      "id": "child-unapproved",
      "when": "Thiếu task-scoped eligibility",
      "visibleUI": "Không cho chọn trẻ",
      "availableActions": [
        "navigate-0",
        "link-settings",
        "link-child-profile-detail"
      ],
      "mutationPolicy": "Actor, exact capability and current versions must still pass; this state never grants rights."
    }
  ],
  "actions": [
    {
      "id": "navigate-0",
      "label": "Giữ phân công trong bản nháp",
      "kind": "submit",
      "targetScreenId": "task-create",
      "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-settings",
      "label": "Cài đặt",
      "kind": "navigate",
      "targetScreenId": "settings",
      "permission": "E",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    },
    {
      "id": "link-child-profile-detail",
      "label": "Bông",
      "kind": "navigate",
      "targetScreenId": "child-profile-detail",
      "permission": "E",
      "confirmationRequired": false,
      "contractRef": "local navigation"
    }
  ],
  "dataBindings": [
    {
      "source": "PATCH /v1/households/{hid}/tasks/{tid}",
      "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": "Ai phụ trách việc này?",
    "primary": "Giữ phân công trong bản nháp",
    "empty": null,
    "notices": [
      "Bông chưa được phụ huynh cho phép làm việc này. Quyền chủ nhà không thay cho xác nhận đó."
    ],
    "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-assignment",
    "nativeRouteStatus": "proposed mapping, verify against implementing native navigator",
    "apiRefs": [
      "PATCH /v1/households/{hid}/tasks/{tid}",
      "PUT /v1/households/{hid}/tasks/{tid}/child-eligibility/{mid}"
    ],
    "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."
    }
  }
}
