{
 "openapi": "3.0.3",
 "info": {
  "title": "FnB SaaS API",
  "version": "0.1.0",
  "description": "Go API for a multi-tenant FnB SaaS (stock, sales, expenses, cashflow) for small restaurants and cafes.\n\n**Auth.** Google Sign-In only. Exchange a Google ID token at `POST /v1/auth/google`; every other call sends `Authorization: Bearer <access token>`. A person is an account that can belong to several merchants, with one role in each. An access token is short-lived and scoped to one merchant, and every query is scoped to it; the client never sends a merchant id or role. `GET /v1/me/merchants` lists the account's merchants and `POST /v1/auth/switch-merchant` returns a token for another one. Staff join through single-use invite links from the owner (valid 30 minutes, max 3 employee accounts per merchant). Roles: `owner`, `manager`, `cashier`, `kitchen` (see `x-roles` per operation). `kitchen` is view-only: the kitchen queue and the session endpoints. `cashier` may also read the queue.\n\n**Tiers & storage caps (binary units).** FREE 100 MiB; MONTHLY 5 GiB; LIFETIME 5 GiB. Storage is the sum of menu item and ingredient image sizes; images are max 1 MiB each. Max 3 employee accounts per merchant (owners excluded) on every tier. Other tier limits are proposed, not final.\n\n**Subscription.** `Merchant.subscription` carries the subscription state, including `wipe_deadline` for a monthly plan whose payment keeps failing.\n\n**Conventions.** Money and quantities are decimal strings. Lists use `limit` (1-100, default 25) and an opaque `cursor`; responses are `{data:[...], next_cursor}` (`next_cursor` null on the last page). Errors: `{error:{code,message,details[],request_id}}`. `close` and `pay` document an optional `Idempotency-Key` header; it is accepted but not enforced yet.\n\n**Images.** 1) `POST .../image/upload-url` returns a presigned PUT URL (5 min). 2) The client PUTs the bytes to that URL (no bearer header). 3) `POST .../image/confirm` checks and stores it. `DELETE .../image` removes it. Responses carry `image.url`, a short-lived URL for the image.\n\nOperations that are planned or internal are not listed here."
 },
 "servers": [
  {
   "url": "https://panly-api-staging.fly.dev",
   "description": "Staging"
  }
 ],
 "security": [
  {
   "bearerAuth": []
  }
 ],
 "tags": [
  {
   "name": "Health"
  },
  {
   "name": "Auth"
  },
  {
   "name": "Merchant & Users"
  },
  {
   "name": "Notifications"
  },
  {
   "name": "Invitations"
  },
  {
   "name": "Onboarding"
  },
  {
   "name": "Plans"
  },
  {
   "name": "Menus"
  },
  {
   "name": "Menu Items"
  },
  {
   "name": "Menu Item Image"
  },
  {
   "name": "Ingredients"
  },
  {
   "name": "Ingredient Image"
  },
  {
   "name": "Shopping list"
  },
  {
   "name": "Recipes"
  },
  {
   "name": "Orders"
  },
  {
   "name": "Expenses"
  },
  {
   "name": "Charges"
  },
  {
   "name": "Stock Audits"
  },
  {
   "name": "Employees & Shifts"
  },
  {
   "name": "Payroll"
  },
  {
   "name": "Reports"
  },
  {
   "name": "Kitchen"
  }
 ],
 "paths": {
  "/healthz": {
   "get": {
    "tags": [
     "Health"
    ],
    "summary": "Liveness probe (no auth, no database call)",
    "operationId": "health",
    "x-roles": [
     "public"
    ],
    "description": "Always 200 while the process is serving. It never touches the database, so the Fly health check on this path does not keep the database awake. Database readiness is `GET /readyz`.",
    "security": [],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Health"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/readyz": {
   "get": {
    "tags": [
     "Health"
    ],
    "summary": "Readiness probe with a database ping (no auth)",
    "operationId": "ready",
    "x-roles": [
     "public"
    ],
    "description": "Pings the database with a 2-second timeout. 200 with `db` `ok` when it is reachable, 503 with `status` `db_unavailable` and `db` `unavailable` otherwise. Not used by the Fly health check.",
    "security": [],
    "responses": {
     "200": {
      "description": "Database reachable",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Ready"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "503": {
      "description": "Database unreachable",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Ready"
        }
       }
      }
     }
    }
   }
  },
  "/v1/auth/google": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Token exchange (Google)",
    "operationId": "auth_google",
    "x-roles": [
     "public"
    ],
    "description": "Google Sign-In is the ONLY way to authenticate; there are no passwords, registration or reset endpoints.\n\nThe client obtains a Google ID token and posts it here. The backend verifies: signature against Google's JWKS, `iss` is `accounts.google.com` or `https://accounts.google.com`, `aud` is one of Panly's OAuth client ids (web and Android), `exp` not passed, `email_verified=true`.\n\nThen: (1) the ACCOUNT is found by `google_sub` (never auto-linked by email alone) or created. (2) If `invite_token` is supplied it is redeemed atomically: the link must exist (404 `INVITE_NOT_FOUND`), be unused (410 `INVITE_USED`), not revoked (410 `INVITE_REVOKED`) and be less than 30 minutes old (410 `INVITE_EXPIRED`); the account must not already be a member (409 `ALREADY_MEMBER`) and the merchant must have fewer than 3 active employees (409 `staff_limit_reached` with `used` and `limit`). On success the account gets a membership with the invited role and the token is scoped to that merchant; on any failure the link is NOT consumed (except that it is single use on success) and no merchant is silently created. (3) Without `invite_token`: the account signs in to its last used merchant (or its first membership); if it has no membership at all, a new FREE merchant and an `owner` membership are created (`merchant_name` optional). Inactive accounts get 403 `account_inactive`.\n\nPAN-397 registration lock (staging only, `REGISTRATION_LOCK_ENABLED`): while Command Center has registration closed, a sign in that would create the account's first business answers 403 `REGISTRATION_CLOSED` unless the verified Google email is on the Command Center whitelist (exact match, case-insensitive). It is checked before the business code, so the first call (no `business_code` yet) is already refused, and the account row that call created is removed again. `error.details.email` is the caller's own Google email. Existing members, invite redemption and staff logins are never refused.\n\nThe returned JWT is scoped to ONE merchant. To work in another merchant of the same account use `GET /v1/me/merchants` and `POST /v1/auth/switch-merchant`. merchant_id and role are NEVER read from the client; they come from `merchant_memberships` and are embedded in our own access JWT.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/GoogleAuthRequest"
       },
       "example": {
        "id_token": "eyJhbGciOiJSUzI1NiIs..."
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/TokenResponse"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "description": "`account_inactive`: the account is turned off. `REGISTRATION_CLOSED` (PAN-397, staging only): new owner sign ups are closed and this Google email is not whitelisted; `details.email` is the refused email.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "REGISTRATION_CLOSED",
          "message": "New owner sign ups are closed",
          "details": {
           "email": "new.person@gmail.com"
          },
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "410": {
      "$ref": "#/components/responses/Gone"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/merchant-codes/{code}/availability": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Check whether a business code is free (public)",
    "operationId": "merchant_code_availability",
    "x-roles": [
     "public"
    ],
    "description": "PAN-107. No sign-in needed, so a sign-up screen can check a code before the person signs in. The code is trimmed and read case-insensitively. Always 200 with `available` and a `reason`: `null` when available, otherwise `taken`, `reserved`, `too_short`, `too_long` or `invalid_characters`. Rules: 3-16 characters, A-Z and 0-9 only, not on the reserved list (admin, api, panly, root, staging, support, ...). The answer is advisory: the create call is what decides (409 `business_code_taken` if someone else got it first). Rate limited per client address (30 calls per minute): 429 `rate_limited` with a `Retry-After` header in seconds. A code is reusable after its business has been fully purged.",
    "security": [],
    "parameters": [
     {
      "name": "code",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "example": "KOPISENJA"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/CodeAvailability"
        },
        "example": {
         "available": false,
         "reason": "taken"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/auth/employee/login": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Staff sign-in (employee ID + password)",
    "operationId": "auth_employee_login",
    "x-roles": [
     "public"
    ],
    "description": "PAN-108. For staff logins created by the owner. Returns the same token response as `POST /v1/auth/google`, scoped to the staff member's business and role. The employee ID is case-insensitive. A wrong ID and a wrong password both give 401 `invalid_credentials` (an unknown ID is checked against a dummy hash so the two take the same time). Only after the CORRECT password: 403 `account_deactivated` (deactivated). `setup_incomplete` (403) is RESERVED: it is defined for a login that has a password but whose setup was never finished, a state the API cannot currently produce, so clients may ignore it. A staff member who has not chosen a password yet gets 401 `invalid_credentials` for any password. Missing fields are 422 `validation_failed`. Failed attempts are counted in the database: 5 per employee ID and 30 per client address in 15 minutes; over the limit it is 429 `rate_limited` with a `Retry-After` header and `error.details.retry_after_seconds` (even for the right password). A successful sign-in clears that ID's failures. Google sign-in stays owner-only. PR4: the business code prefix of the employee ID routes the login to the business's shard (no routing table); an unknown business code is 401 `invalid_credentials` like an unknown ID, and a shard that cannot be reached is 503 `shard_not_mapped`.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/EmployeeLoginRequest"
       },
       "example": {
        "employee_code": "KOPISENJA-SARI",
        "password": "correct horse 42"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/TokenResponse"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "503": {
      "$ref": "#/components/responses/ShardNotMapped"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/auth/employee/setup/preview": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Who is this setup link for?",
    "operationId": "auth_employee_setup_preview",
    "x-roles": [
     "public"
    ],
    "description": "PAN-108. Reads a setup link without using it up, so the app can greet the person and show their employee ID. PAN-112: also returns `business_name`, `business_code`, `role`, `role_id` and `role_name`. 404 `setup_link_not_found`, 410 `setup_link_used` or `setup_link_expired`.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/EmployeeSetupPreviewRequest"
       },
       "example": {
        "token": "stp_..."
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/EmployeeSetupInfo"
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "410": {
      "$ref": "#/components/responses/Gone"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "503": {
      "$ref": "#/components/responses/ShardNotMapped"
     }
    }
   }
  },
  "/v1/auth/employee/setup": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Choose a password with a setup link",
    "operationId": "auth_employee_setup",
    "x-roles": [
     "public"
    ],
    "description": "PAN-108. Spends the single-use setup link (valid 7 days, only its SHA-256 is stored): sets the password and signs the person in (same token response as login). Password: 8-128 characters and not the employee ID; otherwise 422 `validation_failed` on `password` (`required`, `too_short`, `too_long`, `same_as_employee_code`) and the link stays usable. 404 `setup_link_not_found`; 410 `setup_link_used` or `setup_link_expired`; 403 `account_deactivated`.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/EmployeeSetupRequest"
       },
       "example": {
        "token": "stp_...",
        "password": "correct horse 42"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/TokenResponse"
        }
       }
      }
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "410": {
      "$ref": "#/components/responses/Gone"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "503": {
      "$ref": "#/components/responses/ShardNotMapped"
     }
    }
   }
  },
  "/v1/auth/employee/forgot-password": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Forgot password (staff), email a reset link",
    "operationId": "auth_employee_forgot_password",
    "x-roles": [
     "public"
    ],
    "description": "PAN-111. Self-service reset for a staff login that has a contact email. Scope and reasoning: owners sign in with Google and have no password, and a staff login created without an email has nobody to write to, so for those the owner or a manager issues the link (`POST /v1/staff/{staffId}/reset`). Only staff logins with an `email` can use this. Non-enumerating: the answer is always 202 with the same body, whether or not the employee ID exists, is active, has an email, or mail is configured; the email, if any, is sent in the background. A syntactically missing `employee_code` is 422. Rate limit (counted for every request, known ID or not): 3 per employee ID and 10 per client IP per hour, then 429 `rate_limited` with `Retry-After`. The link (`{app}/staff-reset?token=rst_...`) is single use, only its SHA-256 is stored, and it expires after 1 hour; a newer request replaces an older unused link. Complete it with `POST /v1/auth/employee/reset-password`. Link-token note (setup `stp_`, reset `rst_`, invite `inv_`): tokens are opaque and must be passed back unchanged. Today they are `<prefix>_<random>`; the server also accepts `<prefix>_<BUSINESSCODE>.<random>` (business code upper case, random 43 characters base64url) and will issue that form once identity is shard-only. Clients must not parse or rebuild either form. While email is not configured on the server nothing is sent (the answer is unchanged); staging and local servers then write the link to their own log so the flow can be tried, prod never does.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/EmployeeForgotPasswordRequest"
       },
       "example": {
        "employee_code": "KOPISENJA-SARI"
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "Accepted (always the same body)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ForgotPasswordAccepted"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "503": {
      "$ref": "#/components/responses/ShardNotMapped"
     }
    }
   }
  },
  "/v1/auth/employee/reset-password/preview": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Who is this reset link for?",
    "operationId": "auth_employee_reset_preview",
    "x-roles": [
     "public"
    ],
    "description": "PAN-111. Reads an emailed reset link without using it up. Returns the same fields as the setup preview, including `business_name`, `business_code`, `role` and `role_name`. 404 `reset_link_not_found`, 410 `reset_link_used` or `reset_link_expired`.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/EmployeeSetupPreviewRequest"
       },
       "example": {
        "token": "rst_..."
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/EmployeeSetupInfo"
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "410": {
      "$ref": "#/components/responses/Gone"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "503": {
      "$ref": "#/components/responses/ShardNotMapped"
     }
    }
   }
  },
  "/v1/auth/employee/reset-password": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Choose a new password with a reset link",
    "operationId": "auth_employee_reset_password",
    "x-roles": [
     "public"
    ],
    "description": "PAN-111. Spends the single-use reset link (valid 1 hour): sets the new password under the same rules as setup (8-128 characters, not the employee ID; otherwise 422 `validation_failed` on `password` and the link stays usable), uses up every other open link of that login, ENDS ALL EXISTING SESSIONS (refresh tokens are revoked; access tokens run out within their short life), clears the sign-in lockout and signs the person in (same token response as login). 404 `reset_link_not_found`; 410 `reset_link_used` or `reset_link_expired`; 403 `account_deactivated`.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/EmployeeSetupRequest"
       },
       "example": {
        "token": "rst_...",
        "password": "correct horse 42"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/TokenResponse"
        }
       }
      }
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "410": {
      "$ref": "#/components/responses/Gone"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "503": {
      "$ref": "#/components/responses/ShardNotMapped"
     }
    }
   }
  },
  "/v1/auth/employee/change-password": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Change my password (staff)",
    "operationId": "auth_employee_change_password",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-108. For a signed-in staff login. A wrong `current_password` is 422 `validation_failed` (field `current_password`, issue `incorrect`; not 401, which the app reads as an expired session) and counts toward the same failure limit as login (429). `new_password` follows the setup rules (422 `validation_failed` on `new_password` with issue `required`, `too_short`, `too_long` or `same_as_employee_code`; there is no `weak_password` code, and no other strength rule). On success every session of this person is ended and a fresh token response (new refresh token) is returned. An account that signed in with Google is 403 `not_staff_account`.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/EmployeeChangePasswordRequest"
       },
       "example": {
        "current_password": "correct horse 42",
        "new_password": "another long passphrase"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/TokenResponse"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "503": {
      "$ref": "#/components/responses/ShardNotMapped"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/auth/refresh": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Rotate refresh token",
    "operationId": "auth_refresh",
    "x-roles": [
     "public"
    ],
    "description": "Single-use rotation. Presenting an already-used or revoked refresh token is treated as theft: the whole token family is revoked and 401 `refresh_reuse_detected` is returned. Grace window: if the previous token is presented again within 10 seconds of its rotation, and the token it was rotated into has not been used yet, the answer is 200 with the SAME already-issued access and refresh pair (so parallel refreshes from one app all succeed). After 10 seconds, or once the new refresh token has been used, it counts as reuse and the whole family is revoked. PAN-112, how an app learns that its session ended: there is no separate `session_revoked` code. When sessions are ended on purpose (staff password reset or change, staff deactivation, logout-all) the refresh tokens are revoked, so the next refresh answers 401 `refresh_reuse_detected` and the app should send the person to sign in. Other 401 answers here: `unauthorized` with the message \"Refresh token expired\", \"Account is inactive\" or \"No active membership\". PAN-277: the access token carries the session id (`sid`); once its session is revoked (logout, logout-all, staff reset, deactivation or password reset, owner suspension) every authenticated call with that access token is 401 `unauthorized` (\"Session has been signed out\") at once, on every server. An access token without `sid` (issued before PAN-277) gets the same 401, so the app refreshes once. A deactivated membership is 401 `unauthorized` (\"Membership is no longer active\"). PR4: refresh re-checks the membership and the staff password on the business's shard; a shard that cannot be reached is 503 `shard_not_mapped`.",
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/RefreshRequest"
       },
       "example": {
        "refresh_token": "rt_example"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/TokenResponse"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "503": {
      "$ref": "#/components/responses/ShardNotMapped"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/auth/logout": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Revoke this refresh token family",
    "operationId": "auth_logout",
    "x-roles": [
     "public"
    ],
    "security": [],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/RefreshRequest"
       },
       "example": {
        "refresh_token": "rt_example"
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "No content"
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/auth/logout-all": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Revoke all refresh tokens of the current account (all merchants)",
    "operationId": "auth_logout_all",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "Bearer required. Access tokens already issued live until they expire (<= 15 min).",
    "responses": {
     "204": {
      "description": "No content"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/merchants/me": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Get my merchant (tier, storage usage)",
    "operationId": "merchant_get",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Merchant"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Update my merchant",
    "operationId": "merchant_patch",
    "description": "PAN-90: `currency` is not editable. Any request that contains a `currency` field is 422 `currency_locked`.\nPAN-107: `business_code` is not editable either. Any request that contains it is 422 `business_code_locked`.\nPAN-342 B3: the business's own record is the source of truth for `merchant_name`. On a split deployment a\nchanged name is also copied to the business list (`GET /v1/me/merchants`) right after the update commits.\nIf that copy fails the update is still 200 with the new name; the copy is retried in the background, and the\nlist may show the previous name for up to about a minute. Changing only `timezone` does not touch the list.\n",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/MerchantUpdate"
       },
       "example": {
        "merchant_name": "Warung Kopi Senja",
        "timezone": "Asia/Jakarta"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Merchant"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/auth/switch-merchant": {
   "post": {
    "tags": [
     "Auth"
    ],
    "summary": "Switch to another merchant of the same account",
    "operationId": "auth_switch",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "Bearer required. Issues a NEW access JWT (and rotated refresh token of the same family) scoped to `merchant_id`, with the role the account has THERE. Refused with 403 `NOT_A_MEMBER` if the account has no active membership in that merchant (also for merchants that do not exist, so ids cannot be probed). The refresh token belongs to the account and stays valid; only its merchant scope moves. The old access JWT stays valid for its remaining life (<= 15 min) for the OLD merchant.\nPAN-121 - `merchant_id` is the business code (the immutable 3-16 char A-Z0-9 code, case-insensitive). `business_code` is accepted as an alias, alone or together with `merchant_id`. An unknown code is answered exactly like a foreign merchant (403 `NOT_A_MEMBER`). 422 `validation_failed` with details `merchant_id`/`required` when neither is sent, `merchant_id`/`invalid_characters` for a malformed value or an old uuid id, `business_code`/`invalid_characters` for a malformed alias, and `business_code`/`mismatch` when both are sent and differ.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/SwitchMerchantRequest"
       },
       "examples": {
        "by_code": {
         "value": {
          "business_code": "CAFE42",
          "refresh_token": "rt_example"
         }
        },
        "by_id": {
         "value": {
          "merchant_id": "CAFE42",
          "refresh_token": "rt_example"
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/TokenResponse"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/me/merchants": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "List the merchants I belong to",
    "operationId": "me_merchants",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "All active memberships of the signed-in ACCOUNT with merchant name, tier and the role in each. Session endpoint: allowed for every role including kitchen. Data of other merchants is never returned, only this list. Directory 0013 may source rows from account_merchant_index with a legacy memberships fallback for merchants that have no index row; response shape is unchanged. PAN-342 B3: merchant_name here is a copy kept in step with the business record after every rename; after a failed copy it can lag by up to about a minute.",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/MyMerchant"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/merchants": {
   "post": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Create another merchant for my account",
    "operationId": "merchant_create",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "Owner role (in the current merchant). Creates a new FREE merchant with the caller as its owner; the current token stays scoped to the current merchant, call `POST /v1/auth/switch-merchant` to work in the new one. 409 `MERCHANT_LIMIT` when the account already owns as many merchants as its tier allows (`tier_limits.max_merchants`: FREE 1, MONTHLY 2, LIFETIME 5 until Elmer sets its number; the highest tier among the owned merchants counts). Existing extra merchants are never removed; the account just cannot add more.\n\nPAN-397 registration lock (staging only): an account that owns no active business yet (for example staff with `settings.manage`) opening its first one gets 403 `REGISTRATION_CLOSED` while Command Center has registration closed and its email is not whitelisted, with the email in `error.details.email`. Existing owners are never refused.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/MerchantCreate"
       },
       "example": {
        "merchant_name": "Warung Kopi Senja 2",
        "business_code": "KOPISENJA2"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Merchant"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "description": "`permission_denied` (no `settings.manage`), or `REGISTRATION_CLOSED` (PAN-397, staging only): the account owns no business yet, registration is closed and its email is not whitelisted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "REGISTRATION_CLOSED",
          "message": "New owner sign ups are closed",
          "details": {
           "email": "staff.member@gmail.com"
          },
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/account/export": {
   "post": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Download my data — start a CSV export of every business I own (E1)",
    "operationId": "account_export_create",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [],
    "description": "DELETE-ACCOUNT.md §2.6 (E1). **Owner identity only**, decided on the account in the directory, not on the\nsession's role: a Google account that owns at least one business, or that owns none yet. Staff code sessions,\nmember-only accounts (manager, cashier, kitchen, any custom role, even one that ticks every permission) get\n403 `OWNER_ONLY`. No permission key grants it. It covers only the businesses the account owns.\n\nWorks while the owner's businesses are `pending` (7-day deletion grace), from the restricted\n`account_deletion` session: this route skips the business gates (deletion 423, payment 402) and never wakes a\nshard. Protected businesses (QAK1, TUKANGINID) can be exported (read only).\n\nReturns 202 `{export_id, state:\"queued\"}`. The same `Idempotency-Key` (24 hours), or an export that is still\n`queued` or `running`, returns that export (also 202): one running export per account. The worker then builds\none zip, `panly-export-{YYYYMMDD-HHmm}-WIB.zip`: a folder `{CODE}/` per business with `sales.csv`,\n`item_sales.csv` (PAN-388: item, sold, item_sales, item_sales_after_refunds, plus a Total row),\n`expenses.csv`, `stock_in.csv`, `items.csv`, `staff.csv`, and (E1b) `employees.csv`, `payroll.csv` and\n`shifts.csv` (UTF-8 with BOM, RFC 4180, CRLF; cells starting\nwith `=`, `+`, `-` or `@` are prefixed with `'`), and a top-level `README.txt` (generated time in WIB, currency,\nrow counts, and the 10-year books sentence, UU KUP Pasal 28 ayat 11). Each business is read in one read-only\ntransaction on its own shard. The zip goes to R2 `exports/{account_id}/{export_id}.zip` and lives 24 hours.\nAn email \"Your Panly data is ready. Open Panly to download it.\" goes out when it is ready (no link).\n\nLimits: 3 exports per account per rolling 24 hours, then 429 `TOO_MANY_ATTEMPTS` with `Retry-After`. A business\nthat is `deleting` is 423 `BUSINESS_DELETION_PENDING`. Off until `ACCOUNT_EXPORT_ENABLED=true` (503\n`EXPORT_UNAVAILABLE`).\n",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 255
      }
     }
    ],
    "responses": {
     "202": {
      "description": "Queued, or the export that is already queued or running",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AccountExport"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "description": "`OWNER_ONLY`: not an owner identity",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "423": {
      "description": "`BUSINESS_DELETION_PENDING`: an owned business is already being deleted",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "`TOO_MANY_ATTEMPTS`: 3 exports in the last 24 hours (`Retry-After` set)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "`EXPORT_UNAVAILABLE`: the feature is off, or the deployment has no directory",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/account/export/{id}": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Download my data — export status and a fresh download link (E1)",
    "operationId": "account_export_get",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [],
    "description": "DELETE-ACCOUNT.md §2.6 (E1). Same owner-identity guard as POST, also from the restricted `account_deletion`\nsession. Reads the directory only; the app polls every 5 seconds while the screen is open. Only the caller's own\nexport, otherwise 404. `state` is `queued|running|ready|failed|expired`. While `ready`, `download_url` is a\npresigned R2 GET valid for **15 minutes**, minted fresh on every call (`Cache-Control: no-store`); the first\none is audited as `account_export.downloaded`. After `expires_at` (24 hours) the object is deleted and the\nstate is `expired`. Exports older than 8 days are 404.\n",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Export status",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AccountExport"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "description": "`OWNER_ONLY`: not an owner identity",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   }
  },
  "/v1/account/deletion": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Delete my account — preview what will be deleted, or the scheduled job (D3)",
    "operationId": "account_deletion_preview",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [],
    "description": "DELETE-ACCOUNT.md §8 (D3). **Owner identity only** (same guard as `/v1/account/export`): staff code sessions and\nmember-only accounts are 403 `OWNER_ONLY`; no permission key grants it. Also works from the restricted\n`account_deletion` session during the grace period, and for a Google account that owns no business (Play).\n\n`businesses` are the businesses the account owns: each one is confirmed on its own shard (active owner\nmembership), so the list is exactly what the caller must type. `name` is the business name as stored on the\nshard. `other_memberships` counts businesses where the account is only a member: those businesses survive, only\nthe membership goes. `subscription.renews_at` is set only for an active recurring plan (any tier except FREE and LIFETIME) with no job yet. `job` is\nthe pending deletion job, or null.\n\nWith no job yet, the same blockers as POST apply before the screen opens: 409 `PROTECTED_BUSINESS`\n(`details.codes`) for an owner of QAK1 or TUKANGINID, 409 `BUSINESS_BUSY` while a business is being moved,\nrestored, wiped or deleted. 503 `shard_not_mapped` when an owned business's shard cannot be resolved (no fallback).\nReads only. Works when `ACCOUNT_DELETION_ENABLED` is off; a deployment without a directory is 503\n`ACCOUNT_DELETION_UNAVAILABLE`.\n",
    "responses": {
     "200": {
      "description": "Preview",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AccountDeletionPreview"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "description": "`OWNER_ONLY`: not an owner identity",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "`PROTECTED_BUSINESS` (details.codes) or `BUSINESS_BUSY` (only when no job exists)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "`shard_not_mapped`, or `ACCOUNT_DELETION_UNAVAILABLE` (no directory)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "post": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Delete my account — schedule deletion after a 7-day grace period (D3)",
    "operationId": "account_deletion_create",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [],
    "description": "DELETE-ACCOUNT.md §4 and §8 (D3). Checks, in this order: session (401) → owner identity (403 `OWNER_ONLY`) →\na pending job (409 `DELETION_ALREADY_SCHEDULED` with `details.job`, or `DELETION_ALREADY_RUNNING`) → protected\nbusiness (409 `PROTECTED_BUSINESS`, before any field) → busy business (409 `BUSINESS_BUSY`) → body fields\n(400 `validation_failed` for a missing or oversized field) → rate limit (429 `TOO_MANY_ATTEMPTS`, 5 failed\nconfirmations per account in 15 minutes, `Retry-After`) → confirmation (422) → optional re-auth (401\n`REAUTH_INVALID`) → schedule.\n\n**Confirmation** (`pkg/deletionconfirm`, shared with Command Center instant delete):\n`confirm_email` is NFC-normalised, trimmed and lower-cased, then compared with the account email.\n`confirm_business_names` must hold every owned business name exactly once, in any order (a multiset; each name\nNFC, trimmed, inner whitespace collapsed, simple case fold); a blank entry never matches; an account with no\nbusiness sends `[]`. `confirm_phrase` is trimmed and must equal `I agree to delete this account permanently`\n(case sensitive). Every mismatch comes back in one 422: `error.code` is the first of\n`CONFIRM_EMAIL_MISMATCH`, `CONFIRM_BUSINESSES_MISMATCH`, `CONFIRM_PHRASE_MISMATCH` and `details.fields` lists all\nof them; a business mismatch adds only `details.expected_count` and `details.given_count` (never names or codes).\nFailures are logged (no typed values) and count toward the limit.\n\n`google_id_token` (optional): a Google ID token for the same audience and the same Google account, issued within\nthe last 5 minutes; otherwise 401 `REAUTH_INVALID`. Recorded as `reauth`.\n\n**Scheduling** (one directory transaction): an `account_deletion_jobs` row (`execute_after = requested_at + 7\ndays`, email stored as a SHA-256 hash), one queued row per owned business, every owned business set to\n`deletion_state='pending'` (staff get 423 `BUSINESS_DELETION_PENDING` everywhere), and **every refresh token of\nthe account revoked** (all devices sign out). Then auto-renew is stopped for every recurring plan, whatever the plan type or status (no refund), and an\nemail with the deletion date (WIB) is sent; a reminder goes out 24 hours before. Signing in during the grace\nperiod returns the restricted `account_deletion` session (see `TokenResponse.session_scope`).\n\nThe same `Idempotency-Key` returns the existing job (202). Off until `ACCOUNT_DELETION_ENABLED=true` (503\n`ACCOUNT_DELETION_UNAVAILABLE`). D3 only schedules; nothing is deleted until the deletion runner ships.\n",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "maxLength": 255
      }
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/AccountDeletionConfirm"
       }
      }
     }
    },
    "responses": {
     "202": {
      "description": "Scheduled (or the same job for a repeated Idempotency-Key)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AccountDeletionScheduled"
        }
       }
      }
     },
     "400": {
      "description": "`validation_failed`: malformed JSON, or a missing or oversized field",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "401": {
      "description": "`unauthorized`, or `REAUTH_INVALID` (bad, foreign or stale google_id_token)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "403": {
      "description": "`OWNER_ONLY`: not an owner identity",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "409": {
      "description": "`DELETION_ALREADY_SCHEDULED` (details.job), `DELETION_ALREADY_RUNNING`, `PROTECTED_BUSINESS` (details.codes) or `BUSINESS_BUSY`",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "description": "`CONFIRM_EMAIL_MISMATCH`, `CONFIRM_BUSINESSES_MISMATCH` or `CONFIRM_PHRASE_MISMATCH`; details `{fields:[...], expected_count?, given_count?}`",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "description": "`TOO_MANY_ATTEMPTS`: 5 failed confirmations in 15 minutes (`Retry-After` set)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "`ACCOUNT_DELETION_UNAVAILABLE` (flag off or no directory) or `shard_not_mapped`",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Delete my account — cancel during the grace period (D3)",
    "operationId": "account_deletion_cancel",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [],
    "description": "DELETE-ACCOUNT.md §2.3 and §8 (D3). Cancels a `scheduled` job before `execute_after`: the job becomes\n`cancelled`, every business goes back to `deletion_state='none'` (staff work again), the restricted sessions are\nrevoked, and auto-renew is resumed for the businesses it was stopped on whose paid period has not ended. Returns 200 with a fresh **full**\nsession (`TokenResponse` plus `state:\"cancelled\"`); if no business can be signed into, just\n`{state:\"cancelled\"}`. A job that is `running`, or `scheduled` but due, is 409 `DELETION_ALREADY_RUNNING`. No\njob is 404. Works when `ACCOUNT_DELETION_ENABLED` is off.\n",
    "responses": {
     "200": {
      "description": "Cancelled; a fresh full session",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AccountDeletionCancelled"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "description": "`OWNER_ONLY`: not an owner identity",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "description": "`DELETION_ALREADY_RUNNING`",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "503": {
      "description": "`ACCOUNT_DELETION_UNAVAILABLE` (no directory)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/me": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Get the signed-in account, its role here and the current merchant",
    "operationId": "user_me",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Me"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "503": {
      "$ref": "#/components/responses/ShardNotMapped"
     }
    }
   },
   "patch": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Update my account preferences (preferred language)",
    "operationId": "user_me_patch",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-93. Sets the signed-in ACCOUNT's preferred language. `language` is required in the body: a short language code\n(`en`, `id`, `pt-BR`) stores it, `null` clears it (the app follows the device). The code is trimmed and normalised\n(`ID` and ` id ` become `id`, `pt-br` becomes `pt-BR`); anything that is not a 2-3 letter language with an optional\n2-4 letter subtag is 422 `validation_failed`. Returns the same body as `GET /v1/me`. Date format follows the language\nand number format follows the merchant currency; both are formatted in the app, the backend stores nothing else.\n",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/MeUpdate"
       },
       "example": {
        "language": "id"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Me"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/notifications": {
   "get": {
    "tags": [
     "Notifications"
    ],
    "summary": "My notifications in this business, newest first",
    "operationId": "notifications_list",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-147. The signed-in member's own in-app notifications in the current business (one row per recipient; nobody sees another member's rows). Newest first by `created_at`; a deduplicated notification moves back to the top when it fires again. No text is returned: the app renders `type` with `params` and opens `target`. Rows are deleted 90 days after `created_at`, read or not.",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Notification"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/notifications/unread-count": {
   "get": {
    "tags": [
     "Notifications"
    ],
    "summary": "How many of my notifications are unread",
    "operationId": "notifications_unread_count",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-147. Unread notifications of the signed-in member in the current business (the bell badge).",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "count": {
           "type": "integer",
           "minimum": 0,
           "example": 3
          }
         },
         "required": [
          "count"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/notifications/read": {
   "post": {
    "tags": [
     "Notifications"
    ],
    "summary": "Mark my notifications read",
    "operationId": "notifications_read",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-147. Send `{\"ids\": [...]}` (1-200 notification ids) to mark those read, or `{\"all\": true}` to mark every unread notification of the caller in this business read. A body with neither (an empty body, `{}`, `{\"all\": false}` or `{\"ids\": []}`) is 422 `no_targets` and marks nothing; both together is 422 `validation_failed`, as is an id that is not a uuid. Ids that are not the caller's (another member, another business, unknown) are ignored. Returns 204.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/NotificationsRead"
       },
       "examples": {
        "ids": {
         "value": {
          "ids": [
           "0b6f3c1e-1f7a-4d43-9a7e-1c2d3e4f5a6b"
          ]
         }
        },
        "all": {
         "value": {
          "all": true
         }
        }
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "Marked read"
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "422": {
      "description": "`no_targets` (neither ids nor all: true) or `validation_failed`.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "no_targets",
          "message": "Send ids or all: true",
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/permissions": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Permission catalog",
    "operationId": "permissions_list",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "roles.manage"
    ],
    "description": "PAN-89 / PAN-225. Permission catalog in display order. Each entry is\n`{key, group, label_key, requires[]}` where `requires` is the Closure of\nthe key's direct dependencies. Auth: `roles.manage` (delegable) or owner.\n",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/PermissionDef"
           }
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/roles": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "List roles",
    "operationId": "roles_list",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "roles.manage"
    ],
    "description": "PAN-89. Owner, the three starter roles (manager, cashier, kitchen shown as Fulfilment) and the custom roles (oldest first), each with its permissions and member_count. Not paginated (at most 14 entries).",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Role"
           }
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Create a custom role",
    "operationId": "roles_create",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "roles.manage"
    ],
    "description": "PAN-89 / PAN-225. Up to 10 custom roles per merchant (409 `roles_limit_reached`). 409 `role_name_taken`. 422 `validation_failed` (unknown key), `permission_owner_only` or `permission_requires` carry `details[{field: permissions, issue}]`. Non-owner with `roles.manage` may only grant keys they hold (403 `permission_not_held`); owners are unrestricted. Nothing is created on an error.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/RoleCreate"
       },
       "example": {
        "name": "Floor lead",
        "permissions": [
         "orders.view",
         "orders.queue"
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Role"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/roles/{roleId}": {
   "patch": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Rename a custom role or change its permissions",
    "operationId": "roles_patch",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "roles.manage"
    ],
    "description": "PAN-89 / PAN-225. Applies to everyone holding the role on their next request (refresh tokens are NOT revoked on role/permission change — only on member remove/deactivate, PAN-206). Owner and starter roles are read only (409 `role_readonly`). Same create errors; plus 403 `own_role_locked` when the caller edits their own role, 403 `permission_not_held` when granting a key they lack. Unknown id: 404.",
    "parameters": [
     {
      "name": "roleId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Custom role uuid"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/RolePatch"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Role"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Delete a custom role",
    "operationId": "roles_delete",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "roles.manage"
    ],
    "description": "PAN-89 / PAN-225. 409 `role_in_use` (with `error.member_count`) while any member, deactivated ones included, holds the role: move them first with `PATCH /v1/members/{id}` `{role_id}`. Pending invitations for the role are removed. Owner and starter roles: 409 `role_readonly`. 403 `own_role_locked` when deleting the caller's own role.",
    "parameters": [
     {
      "name": "roleId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      },
      "description": "Custom role uuid"
     }
    ],
    "responses": {
     "204": {
      "description": "Deleted",
      "headers": {
       "Panly-Charge-Delete": {
        "description": "PAN-391. `hard` (removed for good) or `soft` (hidden, kept for past numbers).",
        "schema": {
         "type": "string",
         "enum": [
          "hard",
          "soft"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/members": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "List members (memberships) of my merchant",
    "operationId": "members_list",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "staff.manage"
    ],
    "parameters": [
     {
      "name": "role_id",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "PAN-89. Only members with this role (`owner`, `manager`, `cashier`, `kitchen` or a custom role uuid). Used for \"See who\" and for moving people before a role is deleted. Anything else is 422."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Member"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/members/{membershipId}": {
   "patch": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Change role / deactivate a member",
    "operationId": "member_patch",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "staff.manage"
    ],
    "description": "PAN-89: send `role_id` (a starter id or a custom role uuid) to change the role; deactivated members keep their role. Cannot demote or deactivate the last active owner (409). Reactivating, or changing an owner into manager/cashier/kitchen, is subject to the 3-employee cap: 409 `staff_limit_reached` (`used`, `limit`). Deactivating an employee frees the slot. Only this merchant's membership changes; the account and its other memberships are untouched.",
    "parameters": [
     {
      "name": "membershipId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the member"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/MemberUpdate"
       },
       "example": {
        "role": "manager",
        "is_active": true
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Member"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/staff": {
   "post": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Create a staff login (employee ID + setup link)",
    "operationId": "staff_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "description": "PAN-108. Owner or manager. PAN-109 manager rule: the owner can manage anyone. A manager can create staff and list, read, edit, deactivate, reset and delete NON-manager staff (cashier, kitchen, custom roles), but cannot create, edit, deactivate, reset or delete another manager (or themself), cannot make anyone a manager, and cannot touch the owner: 403 `forbidden_manager_target` (target or requested role is a manager) or `forbidden_owner_target` (the login belongs to the owner). Only the owner can do those. Other roles get 403 `permission_denied`. Managers can still read the list and see managers. Creates a staff member who signs in with an employee ID and a password instead of Google. The employee ID is `{BUSINESSCODE}-{USERNAME}`: the business code comes from the business, `username` is the part the owner chooses (3-20 characters: letters, digits, `.` and `_`; case-insensitive, stored upper case; it is fixed once created). Role: `role_id` (manager, cashier, kitchen or a custom role uuid) or `role`; `owner` is refused. There is no password yet: the response carries a one-time `setup_link` (valid 7 days, shown only here; its token is opaque, see the link-token note on `POST /v1/auth/employee/forgot-password`) for the owner to hand over; the staff member opens it and chooses a password (`POST /v1/auth/employee/setup`). Staff logins count toward the 3 employee accounts per business (only ACTIVE ones: deactivated staff and the owner do not count, so deactivating frees a slot and reactivating re-checks) (409 `staff_limit_reached` with `used`/`limit`). Optional `email` (PAN-111): a contact address stored lower case on the login (not a sign-in name; members never show it). When present and mail is on, the setup link is also emailed to it (`email_queued: true` means handed to the provider, not delivered); the response still carries `setup_link`. 422 `validation_failed` on `email` (`invalid`). 409 `employee_code_taken` when the ID exists. 422 `validation_failed` on `username` (`required`, `too_short`, `too_long`, `invalid_characters`), `name` or `role_id`.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/StaffCreate"
       },
       "example": {
        "name": "Sari Wulandari",
        "username": "sari",
        "role": "cashier"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StaffCreated"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "List staff logins",
    "operationId": "staff_list",
    "x-roles": [
     "owner",
     "manager"
    ],
    "description": "PAN-108. Owner or manager (PAN-109: a manager sees managers too). Staff logins of this business, oldest id first. `setup_status` is `pending` until the person has chosen a password; `setup_expires_at` is when the newest unused setup link stops working. Never returns a password, a hash or a link.",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Staff"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          },
          "seats": {
           "$ref": "#/components/schemas/StaffSeats"
          }
         },
         "required": [
          "data",
          "seats"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/staff/id-availability": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Is this employee ID free?",
    "operationId": "staff_id_availability",
    "x-roles": [
     "owner",
     "manager"
    ],
    "description": "PAN-112. Checks the chosen part of an employee ID in the signed-in business (same normalisation and limits as `username` on `POST /v1/staff`: trimmed, case-insensitive, 3-20 characters of letters, digits, `.` and `_`). `id` may also be the full ID of this business (`KOPISENJA-SARI`); an ID with another business code is `invalid_characters`. Always 200 with `{available, reason}`. `reason` is null when available, else `required` (blank), `too_short`, `too_long`, `invalid_characters` or `taken`. Owner or manager only (403 `permission_denied` otherwise). Rate limit: 60 checks a minute per signed-in account, then 429 `rate_limited` with `Retry-After`. The answer is advisory: `POST /v1/staff` still returns 409 `employee_code_taken` if somebody wins the race.",
    "parameters": [
     {
      "name": "id",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string"
      },
      "example": "sari",
      "description": "The chosen part of the employee ID, or the full ID."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StaffIDAvailability"
        },
        "examples": {
         "free": {
          "value": {
           "available": true,
           "reason": null
          }
         },
         "taken": {
          "value": {
           "available": false,
           "reason": "taken"
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/staff/{staffId}": {
   "get": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Get one staff login",
    "operationId": "staff_get",
    "x-roles": [
     "owner",
     "manager"
    ],
    "description": "PAN-108. Owner or manager. 404 for an id that belongs to another business.",
    "parameters": [
     {
      "name": "staffId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the staff login (the `id` from `GET /v1/staff`)."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Staff"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Rename, change role, deactivate or reactivate a staff login",
    "operationId": "staff_patch",
    "x-roles": [
     "owner",
     "manager"
    ],
    "description": "PAN-108. Owner or manager, with the PAN-109 manager rule (403 `forbidden_manager_target` / `forbidden_owner_target`; promoting anyone to manager or changing a manager is owner-only). Any of `name`, `role_id` (or `role`), `is_active` and `email` (PAN-111; null or empty removes it; 422 `invalid` on a bad address). Deactivating ends the person's sessions at once; they can no longer sign in (403 `account_deactivated` after the right password) and the slot is freed. Reactivating is subject to the staff seat cap (409 `staff_limit_reached` with `used`/`limit`). The employee ID cannot change and passwords are never set here: a body containing `employee_code`, `username` or `password` is 422 `employee_code_locked`.",
    "parameters": [
     {
      "name": "staffId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the staff login (the `id` from `GET /v1/staff`)."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/StaffUpdate"
       },
       "example": {
        "name": "Sari W.",
        "is_active": false
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Staff"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Delete a staff login",
    "operationId": "staff_delete",
    "x-roles": [
     "owner",
     "manager"
    ],
    "description": "PAN-108. Owner or manager, with the PAN-109 manager rule (a manager can delete non-managers only; 403 `forbidden_manager_target` / `forbidden_owner_target`). Removes the login for good in one transaction: its setup tokens, its device (push) tokens, its sessions and its membership. Orders, kitchen ticks and audit rows keep the staff member's NAME as it was when they were written, and point at nobody. The employee ID becomes free to create again.",
    "parameters": [
     {
      "name": "staffId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the staff login (the `id` from `GET /v1/staff`)."
     }
    ],
    "responses": {
     "204": {
      "description": "Deleted"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/staff/{staffId}/reset": {
   "post": {
    "tags": [
     "Merchant & Users"
    ],
    "summary": "Reset a staff member's password (new setup link)",
    "operationId": "staff_reset",
    "x-roles": [
     "owner",
     "manager"
    ],
    "description": "PAN-108. Owner or manager, with the PAN-109 manager rule (a manager can reset non-managers only; 403 `forbidden_manager_target` / `forbidden_owner_target`). Clears the password, invalidates every earlier setup and reset link (PAN-111: reset links included; if the login has an `email` and mail is on, the new setup link is also emailed, see `email_queued`), ends all sessions and returns a new one-time `setup_link` (valid 7 days). The person cannot sign in until they use it.",
    "parameters": [
     {
      "name": "staffId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the staff login (the `id` from `GET /v1/staff`)."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StaffCreated"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/invitations": {
   "post": {
    "tags": [
     "Invitations"
    ],
    "summary": "Create a single-use invite link (30 minutes)",
    "operationId": "inv_create",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "staff.manage"
    ],
    "description": "Owner only. Link-based, NOT bound to an email. Role: `role_id` (manager, cashier, kitchen or a custom role uuid; PAN-89) or the older `role`. Single use. Expires 30 minutes after creation (`expires_at`). The invitee signs in with Google and sends `invite_token` to POST /v1/auth/google. The token is opaque (`inv_...`; see the link-token note on `POST /v1/auth/employee/forgot-password`). Max 3 employee accounts per merchant (owners excluded): pending invites do NOT reserve a slot, so creation returns 409 `staff_limit_reached` (with `used`/`limit`) when at the seat limit (Go pre-check + SQL), and redemption re-checks atomically in the database.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/InvitationCreate"
       },
       "example": {
        "role": "cashier"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Invitation"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "get": {
    "tags": [
     "Invitations"
    ],
    "summary": "List invitations",
    "operationId": "inv_list",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "staff.manage"
    ],
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Invitation"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/invitations/{invitationId}": {
   "delete": {
    "tags": [
     "Invitations"
    ],
    "summary": "Revoke a pending invitation",
    "operationId": "inv_delete",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "staff.manage"
    ],
    "parameters": [
     {
      "name": "invitationId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the invitation"
     }
    ],
    "responses": {
     "204": {
      "description": "No content"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/menus": {
   "get": {
    "tags": [
     "Menus"
    ],
    "summary": "List menus",
    "operationId": "menus_list",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "items.view"
    ],
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Menu"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Menus"
    ],
    "summary": "Create menu",
    "description": "PAN-128: menu (category) names are unique per merchant, case-insensitive and trimmed. A duplicate returns 409 `category_exists` with `error.existing` {id, name}, the category that already has the name.",
    "operationId": "menus_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/MenuWrite"
       },
       "example": {
        "menu_name": "Main menu"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Menu"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/CategoryExists"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/menus/{menuId}": {
   "get": {
    "tags": [
     "Menus"
    ],
    "summary": "Get menu",
    "operationId": "menus_get",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "items.view"
    ],
    "parameters": [
     {
      "name": "menuId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Menu"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Menus"
    ],
    "summary": "Update menu",
    "description": "PAN-128: renaming onto another category's name (case-insensitive, trimmed) returns 409 `category_exists` with `error.existing` {id, name}. Changing only the case of the menu's own name is allowed.",
    "operationId": "menus_patch",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "parameters": [
     {
      "name": "menuId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/MenuWrite"
       },
       "example": {
        "menu_name": "Main menu (new)"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Menu"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/CategoryExists"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Menus"
    ],
    "summary": "Delete menu (and its items); 409 if it has orders",
    "operationId": "menus_delete",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "parameters": [
     {
      "name": "menuId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu"
     }
    ],
    "responses": {
     "204": {
      "description": "No content"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/menu-items": {
   "get": {
    "tags": [
     "Menu Items"
    ],
    "summary": "List menu items",
    "description": "One page of the merchant's menu items sorted by menu_item_name, then id. Pass the same menu_id and q with each next_cursor; next_cursor is null on the last page. Same paging contract as GET /v1/ingredients. Each item carries its stock summary (recipe_ingredient_count, stock_status, servings_available) and, for owners and managers only, recipe_cost (PAN-73), all computed for the whole page in the same statement.",
    "operationId": "items_list",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "items.view"
    ],
    "parameters": [
     {
      "name": "menu_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "Filter by menu."
     },
     {
      "name": "q",
      "in": "query",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "menu_item_name contains, case-insensitive. Leading and trailing spaces are ignored."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor (name order). 422 if malformed."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/MenuItem"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Menu Items"
    ],
    "summary": "Create menu item",
    "operationId": "items_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/MenuItemWrite"
       },
       "example": {
        "menu_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
        "recipe_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
        "menu_item_name": "Latte",
        "menu_item_desc": "Double espresso, steamed milk",
        "menu_item_price": "30000.00"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/MenuItem"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/menu-items/{menuItemId}": {
   "get": {
    "tags": [
     "Menu Items"
    ],
    "summary": "Get menu item",
    "operationId": "items_get",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "items.view"
    ],
    "parameters": [
     {
      "name": "menuItemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu item"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/MenuItem"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Menu Items"
    ],
    "summary": "Update menu item",
    "operationId": "items_patch",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "description": "menu_id, menu_item_name and menu_item_price are required on every PATCH. menu_item_desc and recipe_id are\noptional and three-state:\n\n- omitted: left unchanged\n- `recipe_id: null` or `\"\"`: clears the link (`recipe_id` becomes null, so the item is no longer stock-tracked)\n- a recipe UUID from the same merchant: links it (422 if it is malformed or belongs to another merchant)",
    "parameters": [
     {
      "name": "menuItemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu item"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/MenuItemWrite"
       },
       "examples": {
        "update": {
         "summary": "Change price, keep the recipe link",
         "value": {
          "menu_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
          "menu_item_name": "Latte",
          "menu_item_price": "32000.00"
         }
        },
        "clear_recipe": {
         "summary": "Unlink the recipe",
         "value": {
          "menu_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
          "menu_item_name": "Latte",
          "menu_item_price": "32000.00",
          "recipe_id": null
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/MenuItem"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Menu Items"
    ],
    "summary": "Delete menu item (also deletes its image object); 409 if ordered",
    "operationId": "items_delete",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "parameters": [
     {
      "name": "menuItemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu item"
     }
    ],
    "responses": {
     "204": {
      "description": "No content"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/menu-items/{menuItemId}/image/upload-url": {
   "post": {
    "tags": [
     "Menu Item Image"
    ],
    "summary": "Request presigned upload URL for menu item image",
    "operationId": "item_img_url",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "description": "Step 1 of 3. Validates `content_type` (image/jpeg, image/png, image/webp) and `size_bytes` (1..1048576 = 1 MiB) and the merchant's storage cap (FREE 100 MiB = 104857600 bytes; MONTHLY and LIFETIME 5 GiB = 5368709120 bytes; binary units). Returns a presigned PUT URL valid 5 minutes for the key `merchants/{business_code}/menu-items/{id}/{uuid}.{ext}` in the env's image bucket.\n\nStep 2: the client PUTs the raw bytes to `upload_url` with the returned headers (no Authorization header).\nStep 3: call `/image/confirm`.",
    "parameters": [
     {
      "name": "menuItemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu item"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ImageUploadUrlRequest"
       },
       "example": {
        "content_type": "image/png",
        "size_bytes": 204800
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ImageUploadUrlResponse"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "413": {
      "$ref": "#/components/responses/StorageCapExceeded"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/menu-items/{menuItemId}/image/confirm": {
   "post": {
    "tags": [
     "Menu Item Image"
    ],
    "summary": "Confirm uploaded menu item image",
    "operationId": "item_img_confirm",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "description": "Step 3. The server HEADs the object in R2, verifies it exists, that the key belongs to this merchant/resource, and that Content-Type is allowed and Content-Length is 1..1048576 bytes (1 MiB) and fits the storage cap; then stores image_key/content_type/size/updated_at and deletes the previous object. 409 `upload_not_found` if the PUT did not happen or expired; on a failed check the uploaded object is deleted.",
    "parameters": [
     {
      "name": "menuItemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu item"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ImageConfirmRequest"
       },
       "example": {
        "object_key": "merchants/CAFE42/menu-items/3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34/3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34.png"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/MenuItem"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/menu-items/{menuItemId}/image": {
   "delete": {
    "tags": [
     "Menu Item Image"
    ],
    "summary": "Remove menu item image",
    "operationId": "item_img_delete",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "description": "Clears the image columns and deletes the R2 object.",
    "parameters": [
     {
      "name": "menuItemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu item"
     }
    ],
    "responses": {
     "204": {
      "description": "No content"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/ingredients": {
   "get": {
    "tags": [
     "Ingredients"
    ],
    "summary": "List ingredients",
    "description": "One page of the merchant's ingredients sorted by ingredient_name, then id. Pass the same q and status with each next_cursor. counts are returned on every page; they respect q but not status, so the All / Low / Out chips always have all three numbers. status=restock returns low and out together (the shopping list); its total is counts.low + counts.out. Each ingredient carries par_quantity, last_supplier, and (with costs.view) last_unit_price and last_purchased_on from the latest non-voided stock-in (PAN-220). Page, counts and those lookups come from one SQL statement.",
    "operationId": "ing_list",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.view"
    ],
    "parameters": [
     {
      "name": "q",
      "in": "query",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Name contains, case-insensitive. PAN-95 ranking when q is set: names that start with q come first, then names that contain it elsewhere, each group in name order (then id). Cursor paging follows that order and stays stable; a cursor from before PAN-95 still works. Without q the order is plain name order."
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "all",
        "low",
        "out",
        "restock"
       ],
       "default": "all"
      },
      "description": "all (default); out: stock_quantity <= 0; low: stock_quantity > 0 and at or under min_quantity (ingredients without min_quantity are never low); restock: low or out (same rules), for the shopping list. Case-insensitive; any other value is a 422."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor (name order)."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Ingredient"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true,
           "description": "Null on the last page."
          },
          "counts": {
           "$ref": "#/components/schemas/IngredientCounts"
          }
         },
         "required": [
          "data",
          "next_cursor",
          "counts"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "503": {
      "$ref": "#/components/responses/ShardNotMapped"
     }
    }
   },
   "post": {
    "tags": [
     "Ingredients"
    ],
    "summary": "Create ingredient",
    "description": "ingredient_name and unit are required. min_quantity (low-stock threshold) and par_quantity (restock target) are optional decimal strings; omit or send null for none. When both are set, par_quantity must be at least min_quantity, otherwise 422 with details [{field: par_quantity, issue: must be at least min_quantity}] (app copy: \"Must be at least the minimum.\").",
    "operationId": "ing_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.manage"
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/IngredientWrite"
       },
       "example": {
        "ingredient_name": "Coffee beans",
        "unit": "g",
        "min_quantity": "500",
        "par_quantity": "2000"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Ingredient"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/ingredients/{ingredientId}": {
   "get": {
    "tags": [
     "Ingredients"
    ],
    "summary": "Get ingredient",
    "operationId": "ing_get",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.view"
    ],
    "parameters": [
     {
      "name": "ingredientId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the ingredient"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Ingredient"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Ingredients"
    ],
    "summary": "Update ingredient name, unit, low-stock minimum or restock target",
    "operationId": "ing_patch",
    "description": "ingredient_name and unit are required. min_quantity and par_quantity are optional and work the same way: omit to leave unchanged, send null to clear, or send a decimal string (up to 3 dp, zero allowed) to set. The stored result must keep par_quantity >= min_quantity when both are set (checked against the current values of any field you omit): a par_quantity below the minimum is 422 [{field: par_quantity, issue: must be at least min_quantity}]; a min_quantity raised above the stored target (without a new par_quantity) is 422 [{field: min_quantity, issue: must be at most par_quantity}]. Nothing is changed on a 422. stock_quantity, avg_unit_cost and last_supplier are not writable here. PAN-95: unit must be one of pcs, g, kg, mg, ml, l (422 validation_failed otherwise); the current unit sent back is always accepted; a different unit is 422 unit_locked [{field: unit, issue: locked}] unless unit_locked is false (legacy), where one of the six is set once and then locks. ingredient_name and unit are required for stock.manage holders (owner and stock.manage are unrestricted). PAN-61/PAN-309: a caller with shopping.manage but not stock.manage may set only min_quantity and par_quantity; ingredient_name and unit may be sent but only unchanged (ingredient_name equal to the stored name ignoring surrounding spaces, unit equal to the stored unit), as the shopping list's Shopping levels save does. A different name or unit, null or a non-string for either, or any other field is 403 permission_denied (permission stock.manage) and changes nothing. A caller with neither permission is 403 permission_denied (permission stock.manage). The 200 Ingredient leaves out avg_unit_cost, last_unit_price and last_purchased_on without costs.view.",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.manage",
     "shopping.manage"
    ],
    "parameters": [
     {
      "name": "ingredientId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the ingredient"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/IngredientWrite"
       },
       "example": {
        "ingredient_name": "Coffee beans",
        "unit": "g",
        "par_quantity": "2500"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Ingredient"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Ingredients"
    ],
    "summary": "Delete ingredient; 409 if used by a recipe",
    "operationId": "ing_delete",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.manage"
    ],
    "parameters": [
     {
      "name": "ingredientId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the ingredient"
     }
    ],
    "responses": {
     "204": {
      "description": "No content"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/ingredients/{ingredientId}/movements": {
   "get": {
    "tags": [
     "Ingredients"
    ],
    "summary": "Stock movement ledger",
    "operationId": "ing_moves",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.view"
    ],
    "parameters": [
     {
      "name": "ingredientId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the ingredient"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "From date (merchant tz)."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "To date."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/StockMovement"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/ingredients/{ingredientId}/waste": {
   "post": {
    "tags": [
     "Ingredients"
    ],
    "summary": "Record waste (negative waste movement at avg cost)",
    "operationId": "ing_waste",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.manage"
    ],
    "parameters": [
     {
      "name": "ingredientId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the ingredient"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/WasteWrite"
       },
       "example": {
        "quantity": "10.000",
        "note": "Spilled"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StockMovement"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/StockConflict"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/ingredients/{ingredientId}/image/upload-url": {
   "post": {
    "tags": [
     "Ingredient Image"
    ],
    "summary": "Request presigned upload URL for ingredient image",
    "operationId": "ing_img_url",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.manage"
    ],
    "description": "Step 1 of 3. Validates `content_type` (image/jpeg, image/png, image/webp) and `size_bytes` (1..1048576 = 1 MiB) and the merchant's storage cap (FREE 100 MiB = 104857600 bytes; MONTHLY and LIFETIME 5 GiB = 5368709120 bytes; binary units). Returns a presigned PUT URL valid 5 minutes for the key `merchants/{business_code}/ingredients/{id}/{uuid}.{ext}` in the env's image bucket.\n\nStep 2: the client PUTs the raw bytes to `upload_url` with the returned headers (no Authorization header).\nStep 3: call `/image/confirm`.",
    "parameters": [
     {
      "name": "ingredientId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the ingredient"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ImageUploadUrlRequest"
       },
       "example": {
        "content_type": "image/png",
        "size_bytes": 204800
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ImageUploadUrlResponse"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "413": {
      "$ref": "#/components/responses/StorageCapExceeded"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/ingredients/{ingredientId}/image/confirm": {
   "post": {
    "tags": [
     "Ingredient Image"
    ],
    "summary": "Confirm uploaded ingredient image",
    "operationId": "ing_img_confirm",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.manage"
    ],
    "description": "Step 3. The server HEADs the object in R2, verifies it exists, that the key belongs to this merchant/resource, and that Content-Type is allowed and Content-Length is 1..1048576 bytes (1 MiB) and fits the storage cap; then stores image_key/content_type/size/updated_at and deletes the previous object. 409 `upload_not_found` if the PUT did not happen or expired; on a failed check the uploaded object is deleted.",
    "parameters": [
     {
      "name": "ingredientId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the ingredient"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ImageConfirmRequest"
       },
       "example": {
        "object_key": "merchants/CAFE42/menu-items/3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34/3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34.png"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Ingredient"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/ingredients/{ingredientId}/image": {
   "delete": {
    "tags": [
     "Ingredient Image"
    ],
    "summary": "Remove ingredient image",
    "operationId": "ing_img_delete",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.manage"
    ],
    "description": "Clears the image columns and deletes the R2 object.",
    "parameters": [
     {
      "name": "ingredientId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the ingredient"
     }
    ],
    "responses": {
     "204": {
      "description": "No content"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/shopping-list": {
   "get": {
    "tags": [
     "Shopping list"
    ],
    "summary": "Saved shopping list",
    "operationId": "shopping_list_get",
    "description": "PAN-373. The business's saved shopping list, all rows in one response (at most 500): rows still to buy first, then rows marked bought, oldest first within each. A row is an ingredient (ingredient_id set; name is the ingredient's current name) or free text (ingredient_id null). Rows only leave the list when a user deletes them; nothing adds or removes rows automatically. The live low and out of stock view stays GET /v1/ingredients?status=restock.",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.view"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/ShoppingListItem"
           }
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/shopping-list/items": {
   "post": {
    "tags": [
     "Shopping list"
    ],
    "summary": "Add a shopping list row",
    "operationId": "shopping_list_add",
    "description": "PAN-373. Send ingredient_id (an ingredient of this business) or name (free text, for example Tisu), not both. quantity, unit and note are optional. An ingredient row with no unit takes the ingredient's unit. An ingredient that already has a row still to buy is 409 already_on_list with that row in error.existing. 422 when ingredient_id is not an ingredient of this business, when both or neither of ingredient_id and name are sent, or for an unknown field. 409 shopping_list_full at 500 rows.",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "shopping.manage",
     "stock.manage"
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ShoppingListItemCreate"
       },
       "example": {
        "name": "Tisu",
        "quantity": "2",
        "unit": "pak"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ShoppingListItem"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Shopping list"
    ],
    "summary": "Clear the shopping list",
    "operationId": "shopping_list_clear",
    "description": "PAN-373. Deletes every row of the saved list for good (Clear all). With bought=true only rows marked bought are deleted. Returns how many rows went.",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "shopping.manage",
     "stock.manage"
    ],
    "parameters": [
     {
      "name": "bought",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "true",
        "false"
       ]
      },
      "description": "true deletes only rows marked bought."
     }
    ],
    "responses": {
     "200": {
      "description": "Deleted",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "deleted": {
           "type": "integer",
           "example": 4
          }
         },
         "required": [
          "deleted"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/shopping-list/items/{itemId}": {
   "patch": {
    "tags": [
     "Shopping list"
    ],
    "summary": "Edit or mark a shopping list row bought",
    "operationId": "shopping_list_patch",
    "description": "PAN-373. Only the fields sent change. name applies to free text rows only (422 on an ingredient row). quantity, unit and note take null to clear. bought true marks the row bought (bought_at is kept if already set), false puts it back to buy; unmarking an ingredient row while another row for that ingredient is still to buy is 409 already_on_list. Any other field is 422.",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "shopping.manage",
     "stock.manage"
    ],
    "parameters": [
     {
      "name": "itemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the shopping list row"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ShoppingListItemPatch"
       },
       "example": {
        "bought": true
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ShoppingListItem"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Shopping list"
    ],
    "summary": "Delete a shopping list row",
    "operationId": "shopping_list_delete",
    "description": "PAN-373. Deletes one row for good. It never comes back by itself.",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "shopping.manage",
     "stock.manage"
    ],
    "parameters": [
     {
      "name": "itemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the shopping list row"
     }
    ],
    "responses": {
     "204": {
      "description": "No content"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/recipes": {
   "get": {
    "tags": [
     "Recipes"
    ],
    "summary": "List recipes",
    "description": "One page of the merchant's recipes, sorted by recipe_name, then id, with their ingredient lines (each with the ingredient's name, unit and stock_quantity) and used_by_items. Pass the same q with each next_cursor.",
    "operationId": "rec_list",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "items.view"
    ],
    "parameters": [
     {
      "name": "q",
      "in": "query",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "recipe_name contains, case-insensitive. Leading and trailing spaces are ignored."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor (name order). 422 if malformed."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Recipe"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Recipes"
    ],
    "summary": "Create recipe with ingredient lines",
    "operationId": "rec_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/RecipeWrite"
       },
       "example": {
        "recipe_name": "Latte",
        "ingredients": [
         {
          "ingredient_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
          "quantity": "18.000"
         }
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Recipe"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/recipes/{recipeId}": {
   "get": {
    "tags": [
     "Recipes"
    ],
    "summary": "Get recipe",
    "operationId": "rec_get",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "items.view"
    ],
    "parameters": [
     {
      "name": "recipeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the recipe"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Recipe"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "put": {
    "tags": [
     "Recipes"
    ],
    "summary": "Replace recipe (name and ingredient lines)",
    "operationId": "rec_patch",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "parameters": [
     {
      "name": "recipeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the recipe"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/RecipeWrite"
       },
       "example": {
        "recipe_name": "Latte",
        "ingredients": [
         {
          "ingredient_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
          "quantity": "20.000"
         }
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Recipe"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Recipes"
    ],
    "summary": "Delete recipe (menu items keep existing, recipe unlinked)",
    "operationId": "rec_delete",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "parameters": [
     {
      "name": "recipeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the recipe"
     }
    ],
    "responses": {
     "204": {
      "description": "No content"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/orders": {
   "get": {
    "tags": [
     "Orders"
    ],
    "summary": "List orders",
    "operationId": "ord_list",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.view"
    ],
    "description": "Conditional polling (PAN-340, same pattern as the kitchen queue, PAN-42): every 200 and 304 carries a strong `ETag` and `Cache-Control: private, no-cache`. The ETag is a hash of exactly this page's orders (status, table, timestamps, every item's quantity, status, note, ticks and shortfall, the bill charges, and every payment and refund), scoped to the merchant and to this request's status, from, to, limit and cursor, and to whether the caller sees costs (costs.view; cost columns count only for those callers). Send the last ETag back in `If-None-Match`; while nothing on the page has changed the request answers 304 Not Modified with no body. A new order, confirm, item edit or tick, void, cancel, close, split payment, refund or bill charge change on the page changes the ETag and the next poll gets 200 with the new body and ETag. If-None-Match uses weak comparison: a W/ prefix is ignored, a comma-separated list and `*` are accepted. Invalid filters are still 422.",
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "open|closed|cancelled"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "From date."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "To date."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "example": "\"ol1-3f2a9c0d1b7e4a5f8c6d2e1f0a9b8c7d\""
      },
      "description": "ETag from a previous response of this page. A match returns 304 Not Modified."
     }
    ],
    "responses": {
     "304": {
      "description": "Not Modified. The page has not changed since the ETag in If-None-Match. No body.",
      "headers": {
       "ETag": {
        "description": "Current strong ETag (same value the client sent).",
        "schema": {
         "type": "string"
        }
       },
       "Cache-Control": {
        "schema": {
         "type": "string",
         "example": "private, no-cache"
        }
       }
      }
     },
     "200": {
      "description": "Success",
      "headers": {
       "ETag": {
        "description": "Strong ETag of this page, built from its orders plus the filters, limit, cursor and cost access.",
        "schema": {
         "type": "string",
         "example": "\"ol1-3f2a9c0d1b7e4a5f8c6d2e1f0a9b8c7d\""
        }
       },
       "Cache-Control": {
        "schema": {
         "type": "string",
         "example": "private, no-cache"
        }
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Order"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Create order (optionally with round 1)",
    "operationId": "ord_create",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.create"
    ],
    "description": "menu_id is optional. Items may come from any of the merchant's menus (menus are categories). order_no is assigned by the server and is unique per merchant.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/OrderCreate"
       },
       "example": {
        "menu_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
        "table_label": "T7",
        "items": [
         {
          "menu_item_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
          "quantity": 2
         }
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/orders/{orderId}": {
   "get": {
    "tags": [
     "Orders"
    ],
    "summary": "Get order with items and balance",
    "operationId": "ord_get",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.view"
    ],
    "description": "Conditional polling (PAN-340): every 200 and 304 carries a strong `ETag` and `Cache-Control: private, no-cache`. The ETag is a hash of the order, its items, bill charges and payments, scoped to the merchant and to whether the caller sees costs. Send it back in `If-None-Match`; while the order has not changed the request answers 304 Not Modified with no body. If-None-Match uses weak comparison (W/ ignored, a list and `*` accepted). A missing order or another merchant's order is always 404, never 304.",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the order"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "example": "\"o1-3f2a9c0d1b7e4a5f8c6d2e1f0a9b8c7d\""
      },
      "description": "ETag from a previous response of this order. A match returns 304 Not Modified."
     }
    ],
    "responses": {
     "304": {
      "description": "Not Modified. The order has not changed since the ETag in If-None-Match. No body.",
      "headers": {
       "ETag": {
        "description": "Current strong ETag (same value the client sent).",
        "schema": {
         "type": "string"
        }
       },
       "Cache-Control": {
        "schema": {
         "type": "string",
         "example": "private, no-cache"
        }
       }
      }
     },
     "200": {
      "description": "Success",
      "headers": {
       "ETag": {
        "description": "Strong ETag of this order, built from the order, items, charges and payments plus cost access.",
        "schema": {
         "type": "string",
         "example": "\"o1-3f2a9c0d1b7e4a5f8c6d2e1f0a9b8c7d\""
        }
       },
       "Cache-Control": {
        "schema": {
         "type": "string",
         "example": "private, no-cache"
        }
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/orders/{orderId}/items": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Add another round of items (\"order more\")",
    "operationId": "ord_add",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.create"
    ],
    "description": "409 `order_not_open` if the order is closed or cancelled. 409 `split_locked` once any part of the order's split is paid (PAN-135). Every menu item must belong to the merchant (422 otherwise). Items are not limited to a single menu.",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the order"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/OrderAddRound"
       },
       "example": {
        "items": [
         {
          "menu_item_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
          "quantity": 1
         }
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/orders/{orderId}/items/{orderItemId}": {
   "patch": {
    "tags": [
     "Orders"
    ],
    "summary": "Update a placed item, tick it ready / served, or move it to preparing / served / cancelled",
    "operationId": "ord_item_patch",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "orders.create",
     "orders.prepare",
     "orders.serve",
     "orders.cancel"
    ],
    "description": "409 `split_locked` for a quantity change or cancelling an item once any part of the order's split is paid (PAN-135); ready/served ticks and moving to preparing or served still work. status, quantity, note, ready and served are each optional, and at least one is required. quantity and note can be changed only while the item is placed (409 `item_not_editable`). Serving writes one stock movement per recipe ingredient in the same transaction. Stock is consumed when the item is served, not when the round is confirmed.\n\nPAN-87 ticks and PAN-367 field permissions. Each field is checked on the server: `ready` and `status: preparing` need `orders.prepare`; `served` and `status: served` need `orders.serve`; `status: cancelled` and `reason` need `orders.cancel`; `quantity` and `note` need `orders.create`. A role missing the key for a field is 403 `permission_denied` (with `permission` set to that key), including a cashier or a custom role with only `orders.create` that tries to cancel a line. `ready: true` only while the line is preparing (409 `item_not_confirmed` while placed). `served: true` needs the ready tick (409 `item_not_ready`); `status: served` still works without it. `ready: false` on a served line is 409 `item_already_served` (undo served first). `served: false` returns the line to preparing, clears served_at and served_by_name, keeps the ready tick and reverses exactly the stock the serve deducted (movements with `reversal_of`; the reports net them out). A cancelled line is 409 `item_cancelled` for every tick; an order that is not open is 409 `order_not_open`. All ticks are idempotent: repeating one returns 200 with the current line. Cancelling a line clears its ticks. The response is the order item; cost fields only for owner and manager.",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the order"
     },
     {
      "name": "orderItemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the order item"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/OrderItemUpdate"
       },
       "example": {
        "status": "served"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/OrderItem"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/orders/{orderId}/close": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Close order (counts as paid)",
    "operationId": "ord_close",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.complete"
    ],
    "description": "Completing an order counts as paid. The request body with `method` is required and there is no unpaid_balance check. Sets status=closed and closed_at and, in the same transaction, inserts one payments row for the total of non-cancelled items when that total is greater than zero (kind payment, status completed, note \"auto: paid on order completion\"). PAN-142: the row's method is the body's `method` (cash, qris, card or transfer). A missing or blank method is 422 `method_required`; any other value is 422 `validation_failed`. Existing `other` rows written before this change are left untouched. The method is ignored when the order closes through a fully paid split (each split payment keeps its own method). 409 `items_still_placed` while any item is still placed. Preparing and served items may be closed; cancelled items are ignored. 409 `split_unpaid` while the order's split is partly paid (PAN-135). **Preparing items are served by the close** (PAN-64): in the same transaction each preparing item becomes `served` and its recipe stock is consumed, writing one `sale` stock movement per recipe ingredient exactly as PATCH to served does, so the payment always matches the stock that left inventory and nothing stays reserved. If a preparing item was not actually made, cancel it (PATCH status cancelled) before closing so it is neither charged nor consumed. The response lists those items as served, the order drops off the kitchen queue and the queue ETag changes. Closing an order that is already closed returns that order and does not insert another payment or consume stock again.",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the order"
     },
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "required": [
         "method"
        ],
        "properties": {
         "method": {
          "type": "string",
          "enum": [
           "cash",
           "qris",
           "card",
           "transfer"
          ],
          "example": "qris",
          "description": "PAN-142. Required. Payment method for the payment row; missing or blank is 422 method_required."
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "description": "method_required when method is missing or blank; validation_failed when method is not cash, qris, card or transfer.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/orders/{orderId}/splits": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Split the bill (PAN-135)",
    "operationId": "ord_split_create",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.complete"
    ],
    "description": "Splits a confirmed, unpaid order into 2 to 50 parts. The order must be open (409 `order_not_open`), have no placed items and at least one live item (409 `order_not_confirmed`) and no payment yet (409 `order_paid`). Before any part is paid a new split replaces the old one; once a part is paid a re-split is 409 `split_locked`, and so are edits that change the total (adding a round, changing a quantity, cancelling an item or the order).\n\n**by_item**: each part has `items: [{order_item_id, quantity}]` with whole-number quantities (>= 1, one entry per line per part). For every non-cancelled order line the quantities across all parts must add up exactly to the line's quantity; otherwise, or when an item is not a live line of this order, 422 `items_mismatch` (`details.lines` lists `{order_item_id, quantity, split_quantity}`). A part's subtotal is unit_price x quantity summed over its items.\n\n**by_amount**: each part has `amount` (> 0, in the business currency's minor units: whole rupiah for IDR, up to 2 dp otherwise) and the amounts must add up exactly to the order total, else 422 `amount_mismatch`.\n\nOrder charges (PAN-129) per part: **by_item** (PAN-391) takes the stored per line charge amounts (`items[].charges` on the order): each part gets the charges of the lines it takes, and a line split across parts shares its charge amount by quantity in whole minor units (each share floored, leftover units to the largest remainders, ties to the later part), so a part never pays a charge that is off for its items. When the line amounts do not add up to the order's charges_total (an order priced before per line amounts), by_item falls back to allocating them in proportion to each part's subtotal, rounded as for by_amount. **by_amount** (also used for an equal split, which the app sends as equal amounts) stays proportional: charges are allocated in proportion to each part's amount, rounded half up to the currency's minor unit, with the rounding remainder on the last part, and the part total is the amount with subtotal = amount - charges_total. Each part has subtotal, charges_total, total and status (unpaid|paid).",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": "ID of the order"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/SplitRequest"
       },
       "examples": {
        "by_item": {
         "value": {
          "mode": "by_item",
          "parts": [
           {
            "items": [
             {
              "order_item_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
              "quantity": 1
             }
            ]
           },
           {
            "items": [
             {
              "order_item_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
              "quantity": 2
             }
            ]
           }
          ]
         }
        },
        "by_amount": {
         "value": {
          "mode": "by_amount",
          "parts": [
           {
            "amount": "50000"
           },
           {
            "amount": "60000"
           }
          ]
         }
        }
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "The new split",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Split"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     }
    }
   }
  },
  "/v1/orders/{orderId}/split": {
   "get": {
    "tags": [
     "Orders"
    ],
    "summary": "Current split with its parts (PAN-135)",
    "operationId": "ord_split_get",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.complete"
    ],
    "description": "Returns the order's current split. 404 `not_found` when the order has no split.",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": "ID of the order"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Split"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     }
    }
   }
  },
  "/v1/orders/{orderId}/splits/{splitId}/parts/{partNo}/pay": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Pay one part of a split (PAN-135)",
    "operationId": "ord_split_part_pay",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.complete"
    ],
    "description": "Pays one part. `method` is cash, qris, card or transfer. Cash needs `cash_received` >= the part total (422 `cash_insufficient`) and the response has `change`; `cash_received` is rejected for other methods. `reference` (up to 255 chars, optional) is for qris, card and transfer. Writes one payments row (kind payment, status completed) for the part total when it is above zero. An already paid part is 409 `part_paid`; if the order total changed after the split (items or charges edited) it is 409 `split_stale` and the order must be split again. When every part is paid the order is completed in the same transaction through the normal order-complete path, exactly like a single payment (PAN-140) - status becomes closed, `paid_at` and `closed_at` are set, preparing items are served and their recipe stock consumed, and Reports count it - and `order_paid` is true. Each paid part is its own payments row with its method, amount, reference and paid_by_name. Idempotency-Key is required: a retry with the same key and body returns the first result. Closing an order whose split is partly paid is 409 `split_unpaid`.",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     },
     {
      "name": "splitId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     },
     {
      "name": "partNo",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer",
       "minimum": 1
      }
     },
     {
      "$ref": "#/components/parameters/RequiredIdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/SplitPartPayRequest"
       },
       "example": {
        "method": "cash",
        "cash_received": "100000"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "The part is paid",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/SplitPartPayment"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     }
    }
   }
  },
  "/v1/menu-items/{menuItemId}/charges": {
   "get": {
    "tags": [
     "Menu Items"
    ],
    "summary": "Item charge settings",
    "operationId": "item_charges_list",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "items.view"
    ],
    "description": "PAN-391 PR2. Every non-deleted charge of the business with this item's setting: mode default (no setting: the charge's own rule), on, off or custom (custom_type and custom_value; a custom fixed value is per unit). applies tells whether a line of this item gets the charge when the order has it. Ordered like GET /v1/charges.",
    "parameters": [
     {
      "name": "menuItemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu item"
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/ItemCharge"
           }
          },
          "next_cursor": {
           "type": "string",
           "nullable": true
          }
         },
         "required": [
          "data",
          "next_cursor"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "put": {
    "tags": [
     "Menu Items"
    ],
    "summary": "Set item charge settings",
    "operationId": "item_charges_set",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "items.manage"
    ],
    "description": "PAN-391 PR2. Saves the listed charges' settings for this item (charges not listed are left alone; mode default removes the setting) and returns the full list. A change applies to orders priced afterwards: open orders are priced live, closed orders keep what they stored at close. The order still decides whether a charge is on the bill at all (removed_charge_ids / added_charge_ids at confirm). Rows are all checked before anything is saved, and every problem is listed in `details` as `{field, issue}` with a per row path, so the app can mark each row; nothing is saved when any row is invalid. Paths and issues: `charges` (at most 100); `charges[i].charge_id` (`invalid`, `listed twice`, or `<id> is not a charge of this business`); `charges[i].mode` (`must be default, on, off or custom`); `charges[i].type` (`required for custom`, `must be percent or fixed`, `only for custom`); `charges[i].value` (`required for custom`, `only for custom`, `required`, `invalid decimal`, `out of range` for a percent outside 0.01 to 100, `must be > 0` or `too large` for fixed; percent has up to 2 decimals). `i` is the 0 based index in the request. Code: 422 invalid_charge_id when every problem is a charge that is not the business's, otherwise 422 validation_failed. type and value sent with mode default are ignored.",
    "parameters": [
     {
      "name": "menuItemId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the menu item"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "charges": {
          "type": "array",
          "maxItems": 100,
          "items": {
           "$ref": "#/components/schemas/ItemChargeWrite"
          }
         }
        },
        "required": [
         "charges"
        ]
       },
       "example": {
        "charges": [
         {
          "charge_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
          "mode": "off"
         }
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/ItemCharge"
           }
          },
          "next_cursor": {
           "type": "string",
           "nullable": true
          }
         },
         "required": [
          "data",
          "next_cursor"
         ]
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/orders/quote": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Price a cart (no writes)",
    "operationId": "order_quote",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.create"
    ],
    "x-side-effects": "none",
    "description": "PAN-391 PR2. Read-only: creates no order and writes nothing. Prices a cart as it would be stored if it were placed and confirmed now, with the same SQL pricing (price_order_lines) that confirm and close store, so the app never computes charges itself. Charges are the business's active default-on charges minus removed_charge_ids plus added_charge_ids, validated like confirm (422 invalid_charge_id, 403 charge_not_removable). Unit prices are the current menu prices. items: 1 to 200 lines, quantity 1 to 9999; an item that is not the business's is 422 validation_failed. Each charge's amount is the sum of its line amounts. A later save of the same cart gives the same charge totals; line shares can only differ by one minor unit where two lines tie exactly on their rounding remainder.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "items": {
          "type": "array",
          "minItems": 1,
          "maxItems": 200,
          "items": {
           "type": "object",
           "properties": {
            "menu_item_id": {
             "type": "string",
             "format": "uuid"
            },
            "quantity": {
             "type": "integer",
             "minimum": 1,
             "maximum": 9999
            }
           },
           "required": [
            "menu_item_id",
            "quantity"
           ]
          }
         },
         "removed_charge_ids": {
          "type": "array",
          "items": {
           "type": "string",
           "format": "uuid"
          }
         },
         "added_charge_ids": {
          "type": "array",
          "items": {
           "type": "string",
           "format": "uuid"
          }
         }
        },
        "required": [
         "items"
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/OrderQuote"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/orders/{orderId}/quote": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Price an open order with added items or changed charges (no writes)",
    "operationId": "order_quote_open",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.create"
    ],
    "x-side-effects": "none",
    "description": "PAN-391. Read-only: writes nothing. Prices an open order as it would stand after adding `items` (POST /v1/orders/{orderId}/items, a new round at today's menu prices) and confirming with `removed_charge_ids` / `added_charge_ids` (POST /v1/orders/{orderId}/confirm), with the same SQL pricing (price_order_lines) the order uses live and stores at close. `items` lists the order's non-cancelled lines first (with `order_item_id`, their own unit prices), then the quoted new lines (`order_item_id` null), in pricing order. Charges: without removed_charge_ids and added_charge_ids the order keeps its charge snapshot (before its first confirm: the active default-on charges); with either list the snapshot is rebuilt from the active charges like confirm (default-on minus removed plus added), validated the same way (422 invalid_charge_id, 403 charge_not_removable). An order's charges only change at a confirm, which needs a placed round, so send the charge lists together with the round's `items` (a quote with charge lists and no items shows the result, but confirm alone would answer 409 NOTHING_TO_CONFIRM). `items` may be empty (e.g. only toggling charges), 0 to 200 lines, quantity 1 to 9999; an order with no lines and no items is 422. 404 not_found for an unknown order, 409 order_not_open when it is closed or cancelled, 409 split_locked when a split part is paid. The order itself is unchanged, so GET /v1/orders/{orderId} still shows its current amounts.",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the open order"
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "items": {
          "type": "array",
          "maxItems": 200,
          "description": "Lines to add. May be empty or omitted.",
          "items": {
           "type": "object",
           "properties": {
            "menu_item_id": {
             "type": "string",
             "format": "uuid"
            },
            "quantity": {
             "type": "integer",
             "minimum": 1,
             "maximum": 9999
            }
           },
           "required": [
            "menu_item_id",
            "quantity"
           ]
          }
         },
         "removed_charge_ids": {
          "type": "array",
          "items": {
           "type": "string",
           "format": "uuid"
          }
         },
         "added_charge_ids": {
          "type": "array",
          "items": {
           "type": "string",
           "format": "uuid"
          }
         }
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/OrderQuote"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/stock-check": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Preview stock for a cart or an unconfirmed round",
    "operationId": "stock_check",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.create"
    ],
    "description": "PAN-85. Roles: owner, manager, cashier (`kitchen` gets 403). Read-only: nothing is reserved or changed.\n\nSend `items` (the cart is only on the device until it is placed), or `order_id` with `round_no` (default 1) and no items to check that unconfirmed round. `quantity` is 1 to 100000 and at most 200 lines. A menu item that is not the business's is 422 `validation_failed`; an unknown order is 404; a round with nothing placed is 409 `NOTHING_TO_CONFIRM`.\n\n`available` = stock minus what other preparing items will still deduct (it can be negative when stock already is). Lines take stock in the order sent, first line first: each line takes min(needed, what is left) of each material, and `can_make` is the smallest floor(left / needed per item) over the line's materials, at most `quantity`. Items without a recipe are never short. `short_by` is what stock cannot cover and is never negative. Lines that share a material are listed under it with their `can_make`. Quantities are decimal strings with 3 places.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/StockCheckRequest"
       },
       "example": {
        "items": [
         {
          "menu_item_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
          "quantity": 100
         }
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StockCheck"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "description": "`NOTHING_TO_CONFIRM`: the round has no placed items.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/orders/{orderId}/confirm": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Confirm a round to the kitchen (with stock check)",
    "operationId": "ord_confirm",
    "x-roles": [
     "owner",
     "manager",
     "cashier"
    ],
    "x-permissions": [
     "orders.create"
    ],
    "description": "Roles: owner, manager, cashier. `kitchen` gets 403 (it is view-only and can neither cancel nor override).\n\nConfirming releases the round's `placed` items to the kitchen (placed -> preparing) after a stock check: for each ingredient, needed (recipe quantity x item quantity) vs stock minus what preparing items already reserve. Stock is only consumed when items are served.\n\n**Shortage.** If anything is short the response is `409 STOCK_SHORTAGE` and nothing is confirmed. The body lists every shortage with the affected `order_item_ids` and a `shortage_token`. The waiter then has two choices:\n- (a) Cancel the affected items: call again with `cancel_item_ids` (status cancelled, `cancel_reason=out_of_stock`, reusing the order item cancel path). Cancellations are applied first and PERSIST; then the stock check re-runs on the remaining items. OK -> confirmed (200). Still short -> 409 again with a fresh list and token. Any invalid id (other order, other round, other merchant, not placed) -> 422 `INVALID_CANCEL_ITEMS` and nothing at all is changed.\n- (b) Process with the remaining stock (PAN-85): call again with `allow_partial=true` (old name `acknowledge_shortages`, still accepted) and the `shortage_token`. Quantities stay as ordered. The round is confirmed and the shortage is recorded on each affected item (`short_quantity`, `short_ingredients`) and in the audit log. A missing or stale token (stock or items changed since) returns 409 again with `token_stale=true` and the fresh list. The 409 body also has `lines`: every line of the round with `can_make` (how many of it the stock covers when the lines take stock in order, first line first) and `limited_by_ingredient_id`. Stock is still deducted when an item is served, and only what is in stock: min(needed, max(stock, 0)) per material, so stock never goes below 0.\n\n**All items cancelled.** Nothing is confirmed; the response is 200 `status=nothing_confirmed`. If every item of the order is now cancelled and no completed payment exists, the order becomes `cancelled` (`order_status=cancelled`); otherwise it stays open (refund first). The auto-cancel also sets `cancelled_at` and `cancelled_by_name` (the caller, named as in Cancel order) in the same transaction (PAN-343).\n\n**Audit.** order_audit_events records `items_cancelled` (ids, reason, round), `shortage_override` (the full shortage list, actor) and `round_confirmed` (ids, overridden), plus `order_auto_cancelled`.",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the order"
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/OrderConfirm"
       },
       "example": {}
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/OrderConfirmResult"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "description": "STOCK_SHORTAGE (nothing confirmed; offer allow_partial with the token, or cancel_item_ids) or ORDER_NOT_OPEN / NOTHING_TO_CONFIRM",
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "$ref": "#/components/schemas/StockShortageError"
          },
          {
           "$ref": "#/components/schemas/Error"
          }
         ]
        }
       }
      }
     },
     "422": {
      "description": "INVALID_CANCEL_ITEMS, invalid_charge_id (PAN-129) or validation error; nothing was changed",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "413": {
      "$ref": "#/components/responses/StorageCapExceeded"
     }
    }
   }
  },
  "/v1/orders/{orderId}/cancel": {
   "post": {
    "tags": [
     "Orders"
    ],
    "summary": "Cancel open order",
    "operationId": "ord_cancel",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "orders.cancel"
    ],
    "description": "Cancels an open order. 409 `split_locked` once any part of the order's split is paid (PAN-135). No payment is written. In the same transaction every item that is not served (status placed or preparing) becomes `cancelled` with cancel_reason `order_cancelled` (PAN-64), which releases the stock that preparing items reserved, and order_audit_events records one `items_cancelled` row (item_ids, reason order_cancelled). Served items stay served: their stock was already consumed when they were served. The order drops off the kitchen queue and the queue ETag changes. 409 `order_not_open` if the order is already closed or cancelled, so a repeated cancel changes nothing (and keeps the first cancel note).\nOptional cancel note (PAN-74): the body may be `{\"note\": \"...\"}`. The note is trimmed; empty or white space only counts as no note. After trimming it may be at most 200 characters (Unicode characters, not bytes), else 422 `cancel_note_too_long` and nothing changes. It is stored on the order as `cancel_note` (returned by order get and list, null when none) and, when items were cancelled, added as `note` to the `items_cancelled` audit row. It is separate from the item-level cancel_reason, which stays `order_cancelled`. No body, an empty body, `{}`, `{\"note\": null}` or a blank note cancel exactly as before. A body that is not valid JSON, or a note that is not a string, is 400 `bad_request`.\nWho and when (PAN-82): a successful cancel also sets `cancelled_at` on the order and records the caller's NAME as `cancelled_by_name` (PAN-84, PAN-105). The name is copied at cancel time, so it stays when that person is later removed or renamed; there is no staff id on the order. Both are returned by cancel, order get and list, and are null for orders that are not cancelled and for orders cancelled before PAN-82. A refused repeat cancel (409) keeps the first values.",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the order"
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/OrderCancel"
       },
       "example": {
        "note": "Customer left before the food came"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Order"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "description": "`cancel_note_too_long`: the trimmed note is longer than 200 characters.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "cancel_note_too_long",
          "message": "Cancel note is too long",
          "details": [
           {
            "field": "note",
            "issue": "max 200 characters"
           }
          ],
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/expense-categories": {
   "get": {
    "tags": [
     "Expenses"
    ],
    "summary": "List expense categories",
    "operationId": "cat_list",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "expenses.view",
     "shopping.manage",
     "stock.manage"
    ],
    "description": "Returns each category's id, name and kind (cogs or opex). There are no amount or total fields.\nexpenses.view lists every category. PAN-309: shopping.manage and stock.manage may also list them\nso Receive into stock / Stock in can pick a cost-of-goods category id; the shape is the same (ids\nand names only, plus kind). A caller with none of those permissions is 403 permission_denied\n(permission expenses.view). The owner is unrestricted.",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/ExpenseCategory"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Expenses"
    ],
    "summary": "Create expense category",
    "operationId": "cat_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "expenses.manage"
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ExpenseCategoryWrite"
       },
       "example": {
        "name": "Packaging",
        "kind": "cogs"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ExpenseCategory"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/charges": {
   "get": {
    "tags": [
     "Charges"
    ],
    "summary": "List bill charges",
    "operationId": "charges_list",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-129. Every charge of the business that is not deleted (active and paused), in `sort_order`. Any member can read them so the cashier can show them at confirm. There are no preset charges: each business makes its own.",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Charge"
           }
          },
          "next_cursor": {
           "type": "string",
           "nullable": true,
           "description": "Always null; the list is not paged."
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Charges"
    ],
    "summary": "Create a bill charge",
    "operationId": "charges_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-129. Owner or manager (anyone else gets 403 `permission_denied`). `name`, `type`, `value` and (PAN-391) `kind` are required; `note` is optional (max 200). `percent` values are 0.01-100 with at most 2 dp; `fixed` values are money greater than 0 with at most 2 dp. Names are unique per business, case-insensitive, among charges that are not deleted (409 `charge_name_taken`). `apply_after` makes the charge apply to the subtotal plus that charge (for example service first, then tax on top); a missing, deleted or other-business id, the charge itself or a loop is 422 `invalid_apply_after`. `sort_order` defaults to the end of the list.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ChargeWrite"
       },
       "example": {
        "name": "Service",
        "type": "percent",
        "kind": "revenue",
        "value": "5",
        "receipt_label": "Service 5%"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Charge"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/charges/{chargeId}": {
   "patch": {
    "tags": [
     "Charges"
    ],
    "summary": "Edit a bill charge",
    "operationId": "charges_update",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-129. Owner or manager. Send any field of ChargeWrite; `receipt_label` and `apply_after` may be null to clear them. Set `active=false` to pause a charge: it is not added to new orders. Orders that already have the charge keep their copy (name, type, value), so edits never change an existing bill.",
    "parameters": [
     {
      "name": "chargeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": "ID of the charge"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ChargeWrite"
       },
       "example": {
        "active": false
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Charge"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Charges"
    ],
    "summary": "Delete a bill charge",
    "operationId": "charges_delete",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-129, PAN-391. Owner or manager. A charge no order has taken (`used_on_orders` false) is deleted for good and its name is free again (hard delete). A charge an order has taken, or one that a deleted charge still applies after (`used_on_orders` true), is hidden from setup and new orders but kept for past orders, Reports and exports (soft delete; Reports label it \"{name} (deleted)\" in periods it was used). The `Panly-Charge-Delete` response header says which: `hard` or `soft`. If another live charge applies after this one the answer is 409 `charge_in_use` with `details.blocking_charges` [{id, name}]; change or delete those first.",
    "parameters": [
     {
      "name": "chargeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": "ID of the charge"
     }
    ],
    "responses": {
     "204": {
      "description": "Deleted"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/expenses": {
   "get": {
    "tags": [
     "Expenses"
    ],
    "summary": "List expenses",
    "operationId": "exp_list",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "expenses.view"
    ],
    "parameters": [
     {
      "name": "category_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": ""
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": ""
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": ""
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor. Pages are ordered newest first by incurred_on, then created_at, then id (PAN-137), so same-day expenses list in the order they were added and paging never skips or repeats a row. Cursors issued before PAN-137 are rejected with 422 validation_failed (field cursor, invalid); restart from the first page."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Expense"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Expenses"
    ],
    "summary": "Create expense (ingredient lines auto-add stock)",
    "operationId": "exp_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "expenses.manage",
     "shopping.manage",
     "stock.manage"
    ],
    "description": "expenses.manage may create any expense (a plain opex or a stock-in with ingredient_lines).\nPAN-309: shopping.manage or stock.manage without expenses.manage may only create a stock-in:\nat least one ingredient_line on a cost-of-goods (kind cogs) category. A plain expense (no\nlines) or a category that is not cogs is 403 permission_denied (permission expenses.manage).\nA caller with none of those permissions is the same 403. The owner is unrestricted.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ExpenseCreate"
       },
       "example": {
        "category_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
        "amount": "100000.00",
        "incurred_on": "2026-10-04",
        "supplier": "Pasar Induk",
        "ingredient_lines": [
         {
          "ingredient_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
          "quantity": "1000.000",
          "line_cost": "100000.00"
         }
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Expense"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/expenses/{expenseId}": {
   "get": {
    "tags": [
     "Expenses"
    ],
    "summary": "Get expense with ingredient lines",
    "operationId": "exp_get",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "expenses.view"
    ],
    "parameters": [
     {
      "name": "expenseId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the expense"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Expense"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Expenses"
    ],
    "summary": "Edit a plain expense",
    "operationId": "exp_update",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "expenses.manage"
    ],
    "description": "Partially updates a plain expense: one with no ingredient lines that no payroll run is linked to. Only the owner\nor a manager may edit (anyone else gets 403 `permission_denied`). Send any of `category_id`, `amount`,\n`incurred_on`, `supplier` or `note`, plus an optional `reason`; omitted fields are left unchanged,\n`supplier: null` / `note: null` (or `\"\"`) clear them, and `null` for `category_id`, `amount` or `incurred_on` is\nrejected. A body that changes nothing (empty, only `reason`, or the current values) returns 422 `no_changes`.\nA deleted expense returns 409 `expense_deleted`. Each successful edit writes one amendment (see\n`GET /v1/expenses/{expenseId}/history`) with the old and new value of every changed field. Ingredient lines\ncannot be changed here.\n\nStock purchases (any ingredient lines) return 409 `expense_has_ingredient_lines`; payroll expenses return 409\n`expense_is_payroll`. `locked_reason` on the expense (`stock`, `payroll` or `null`) tells the client up front;\nit comes from the same rule as these guards. On success daily_financials is refreshed in the same transaction for the expense's\nincurred_on, and also for the previous day when incurred_on changed. Returns the full expense, as GET does.",
    "parameters": [
     {
      "name": "expenseId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the expense"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ExpensePatchRequest"
       },
       "example": {
        "amount": "125000.00",
        "incurred_on": "2026-10-03",
        "reason": "Wrong receipt"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Updated expense",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Expense"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Expenses"
    ],
    "summary": "Delete a plain expense",
    "operationId": "exp_delete",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "expenses.manage"
    ],
    "description": "Soft-deletes a plain expense (no ingredient lines, not linked to a payroll run): it disappears from lists,\nGET (404), reports and cashflow, but its history stays readable. Only the owner or a manager may delete.\nThe optional body `{\"reason\": \"...\"}` is saved on the delete amendment. A second delete returns 409\n`expense_deleted`. Stock purchases return 409 `expense_has_ingredient_lines`; payroll expenses return 409\n`expense_is_payroll`; `locked_reason` on the expense predicts both. daily_financials for the expense's\nincurred_on is refreshed in the same transaction.",
    "parameters": [
     {
      "name": "expenseId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the expense"
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ExpenseDeleteRequest"
       },
       "example": {
        "reason": "Entered twice"
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "Deleted"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     }
    }
   }
  },
  "/v1/reports/daily/{day}/entries": {
   "get": {
    "tags": [
     "Reports"
    ],
    "summary": "Source entries behind one day of the daily financials (PAN-156 / PAN-227)",
    "operationId": "rpt_day_entries",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "reports.cashflow",
     "stock.view",
     "stock.correct",
     "stock.void",
     "finance.amend"
    ],
    "description": "Lists the entries that make up one metric of one local business day (the merchant's timezone, the same buckets as `GET /v1/reports/cashflow`), oldest first, so the app can open an entry and correct it. `metric`: `sales` (closed orders), `cogs` (sale stock movements), `waste` (live waste entries; a corrected entry shows only its current version), `opex` (expenses net of their stock lines) and `purchases` (purchase lines of stock expenses, by `incurred_on`). `total` is the day's figure from daily_financials (`total_sales`, `cost_of_sales`, `waste_cost`, `operating_expenses`; purchases sum the live lines). `include_voided=true` (purchases only) returns voided lines even when void soft-deleted the parent expense; `total` stays live-only. PAN-227: route opens with any of `reports.cashflow`, `stock.view`, `stock.correct`, `stock.void`, or `finance.amend` (withPerm OR of stored keys — Requires Closure is not expanded at check time). Without `reports.cashflow`, only `metric=purchases` (stock-in) is allowed; other metrics return 403 `permission_denied` for `reports.cashflow`. `unit_cost` still requires `costs.view`. PAN-201 (comment 10504): without `costs.view`, the cost metrics `purchases`, `cogs` and `waste` also omit each entry's `amount` and the page `total` (keys absent, not null, like Ingredient cost keys and the cashflow report's `cost_of_sales` / `waste_cost`); `quantity`, `unit`, `title` and the rights flags stay, so a `stock.view` role keeps the stock-in history. The request is still 200, not 403. `sales` and `opex` amounts are not cost figures and are unchanged. Owner and any role with `costs.view` see every field. Each entry has `id`, `created_by_name`, `at` and the caller's rights. For a purchase line, `can_amend` / `can_edit` follow `finance.amend` or the creator window; `can_void` requires `stock.void`, the creator window, or `stock.override` (PAN-335: `finance.amend` and `stock.correct` do not void); `can_correct` requires `stock.correct` or `stock.override`. Waste `can_amend` / `can_void` stay on `finance.amend`. A plain opex expense is amendable/deletable only for the owner or a manager with `expenses.manage` (use the PAN-126 `PATCH`/`DELETE /v1/expenses/{expenseId}`). Sales and cost of sales follow their orders and are never amendable here (`locked_reason: order`). `amended` says the entry has correction history (`GET /v1/finance/amendments?entity_id=`).",
    "parameters": [
     {
      "name": "day",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date",
       "example": "2026-10-27"
      }
     },
     {
      "name": "metric",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "sales",
        "cogs",
        "waste",
        "opex",
        "purchases"
       ]
      }
     },
     {
      "$ref": "#/components/parameters/Limit"
     },
     {
      "$ref": "#/components/parameters/Cursor"
     },
     {
      "name": "include_voided",
      "in": "query",
      "schema": {
       "type": "boolean",
       "default": false
      },
      "description": "PAN-202. When true and metric=purchases, include voided purchase lines (and their soft-deleted parent expense). Day total still excludes voided lines.\n"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DayEntriesPage"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/expense-lines/{lineId}": {
   "get": {
    "tags": [
     "Expenses"
    ],
    "summary": "Get a purchase line by id (PAN-395)",
    "operationId": "exp_line_get",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "reports.sales",
     "reports.cashflow",
     "expenses.view",
     "stock.view",
     "stock.correct",
     "stock.void",
     "finance.amend"
    ],
    "description": "Returns one purchase (stock-in) line as a DayEntry, including voided lines.\nThe delivery page uses this when opened by a direct link or reload, if the line\nis not already in memory. 404 if the line is missing, belongs to another\nbusiness, or is a non-voided line on a deleted expense.\nWithout costs.view, `amount` and `unit_cost` are omitted (same as\n`GET /v1/reports/daily/{day}/entries?metric=purchases`).\n",
    "parameters": [
     {
      "$ref": "#/components/parameters/LineId"
     }
    ],
    "responses": {
     "200": {
      "description": "The purchase line",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/DayEntry"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Expenses"
    ],
    "summary": "Amend a purchase line (PAN-156 / PAN-202)",
    "operationId": "exp_line_amend",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "Corrects a purchase (stock expense) line (PAN-156). PAN-225: requires stock.correct (or owner / stock.override). Previously (PAN-202) also allowed with finance.amend, stock.void,\nor for the line creator within 24h merchant-local / while stock_unused (checked in-handler).\nUnusual qty/cost without confirm_unusual → 422 unusual_value. Accounting-safe reversal+replacement\nas in PAN-156. Voided line → 409 line_voided; deleted expense → 409 expense_deleted.\nWithout costs.view (PAN-318): `amendment.before` / `after.line_cost` is kept, matching `line.line_cost`\nand `GET /v1/finance/amendments` (PAN-313); `unit_cost` / `avg_unit_cost` (at every depth) and\n`amendment.before` / `after.amount` stay omitted.\n",
    "parameters": [
     {
      "$ref": "#/components/parameters/LineId"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PurchaseLineAmend"
       },
       "example": {
        "quantity": "2",
        "unit": "kg",
        "line_cost": "60000",
        "reason": "Typo, 2,000,600 g was entered instead of 2 kg"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Amended",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PurchaseLineResult"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/StockConflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/expense-lines/{lineId}/void": {
   "post": {
    "tags": [
     "Expenses"
    ],
    "summary": "Void a purchase line (PAN-156 / PAN-202)",
    "operationId": "exp_line_void",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "Reverses the line's purchase stock movement, sets voided_at (line_cost kept for original_amount), and adjusts the live expense amount.\nPAN-219: voiding the last live line does NOT soft-delete the expense — expense_deleted is always false;\nGET /v1/expenses/{id} still returns the expense (amount 0) with voided lines for the audit trail.\nPAN-335: requires stock.void, the PAN-202 creator window, or owner / stock.override. finance.amend\nand stock.correct do not grant void (a role with those keys and no stock.void is 403\npermission_denied). PAN-351: voiding an already-voided line is always 409 `line_voided`, for every\ncaller (owner, stock.override, stock.void, or a role without void rights), before the permission\ncheck and the body; it is never 403 `permission: voided`. PAN-218: stock.override bypasses window\nand insufficient_stock locks; when reverse would go negative, omit confirm_negative_stock → 409 with\ncan_override/resulting_stock; confirm_negative_stock=true applies (stock may go negative) and the\nfinance_amendments after object records negative_override + stock_before/stock_after. Without\nstock.override, confirm_negative_stock is ignored. reason required.\nWithout costs.view (PAN-318): `amendment.before` / `after.line_cost` is kept, matching `line.line_cost`\nand `GET /v1/finance/amendments` (PAN-313); `unit_cost` / `avg_unit_cost` (at every depth) and\n`amendment.before` / `after.amount` stay omitted.\n",
    "parameters": [
     {
      "$ref": "#/components/parameters/LineId"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/VoidPurchaseLineBody"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Voided",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PurchaseLineResult"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "description": "`line_voided` (PAN-351): the line is already voided; nothing is written. Any caller, any body.\n`insufficient_stock` (PAN-170 / PAN-218): reversing the purchase would take the ingredient below\nzero; `details` has `ingredient_id`, `available`, `required`, and for `stock.override` holders\n`can_override: true` and `resulting_stock` (retry with `confirm_negative_stock: true`).\n",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "examples": {
         "line_voided": {
          "value": {
           "error": {
            "code": "line_voided",
            "message": "This purchase line was voided",
            "request_id": "req_01HX0000"
           }
          }
         },
         "insufficient_stock": {
          "value": {
           "error": {
            "code": "insufficient_stock",
            "message": "Not enough stock: this change would take the ingredient below zero",
            "details": {
             "ingredient_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
             "available": "2.000",
             "required": "10.000"
            },
            "request_id": "req_01HX0000"
           }
          }
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/expense-lines/{lineId}/correct": {
   "post": {
    "tags": [
     "Expenses"
    ],
    "summary": "Correct a purchase line in place (PAN-222)",
    "operationId": "exp_line_correct",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "Edits the purchase line in place (same id, same incurred_on date). Updates the live\npurchase stock_movement quantity/cost, applies a stock delta, and recosts later\nsale/waste movements until the next purchase (exclusive). Writes finance_amendments\naction=`corrected` (and `recosted` per touched movement). Never writes reason=waste.\nPAN-225: stock.correct (or owner / stock.override). PAN-218 stock.override + confirm_negative_stock applies to\nboth same-ingredient deltas and ingredient-change reverse (owner/override: omit confirm → 409 with\ncan_override; confirm_negative_stock=true applies with audit/movement negative_override; staff keep the\nnormal guard). Ingredient change still rebuilds under the same line id. confirm_unusual when thresholds cross.\nHistory stays a single row with DayEntry.corrected + original_quantity.\nWithout costs.view (PAN-318): `amendment.before` / `after.line_cost` is kept, matching `line.line_cost`\nand `GET /v1/finance/amendments` (PAN-313); `unit_cost` / `avg_unit_cost` (at every depth) and\n`amendment.before` / `after.amount` stay omitted.\n",
    "parameters": [
     {
      "$ref": "#/components/parameters/LineId"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PurchaseLineCorrect"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Corrected in place",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/CorrectPurchaseResult"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/StockConflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/expense-lines/{lineId}/history": {
   "get": {
    "tags": [
     "Reports"
    ],
    "summary": "On-demand audit trail of a purchase line (PAN-221)",
    "operationId": "exp_line_history",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "reports.sales",
     "reports.cashflow",
     "expenses.view",
     "stock.view",
     "stock.correct",
     "stock.void",
     "finance.amend"
    ],
    "description": "Keyset-paginated correction history of one purchase line, newest first. Loaded only when\nthe client requests it; list and detail payloads do not include it. Recosted later sales\nand waste are not in `data`. When any exist, `recost_summary` has the count and\n`expandable: true`; load them with `GET /v1/expense-lines/{lineId}/recosts`.\n`changes` is the presented field list (quantity, line_cost, stock, and so on). Flag-only\nkeys such as `original_quantity` and `corrected` are omitted. The synthetic create reason\nis omitted. `actor_name` is never the literal Unknown; when nobody can be named it is\n\"Nama tidak tersedia\".\nWithout `costs.view`, purchase `line_cost` is kept (PAN-313); `unit_cost` / `avg_unit_cost`\n/ waste `amount` are omitted.\n",
    "parameters": [
     {
      "name": "lineId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": "ID of the purchase line"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor.",
      "200": {
       "description": "Success",
       "content": {
        "application/json": {
         "schema": {
          "$ref": "#/components/schemas/AuditHistoryPage"
         }
        }
       }
      },
      "401": {
       "$ref": "#/components/responses/Unauthorized"
      },
      "403": {
       "$ref": "#/components/responses/Forbidden"
      },
      "404": {
       "$ref": "#/components/responses/NotFound"
      },
      "422": {
       "$ref": "#/components/responses/Unprocessable"
      },
      "429": {
       "$ref": "#/components/responses/RateLimited"
      }
     }
    ]
   }
  },
  "/v1/expense-lines/{lineId}/recosts": {
   "get": {
    "tags": [
     "Reports"
    ],
    "summary": "On-demand recost rows of a purchase line (PAN-221)",
    "operationId": "exp_line_recosts",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "reports.sales",
     "reports.cashflow",
     "expenses.view",
     "stock.view",
     "stock.correct",
     "stock.void",
     "finance.amend"
    ],
    "description": "Keyset-paginated recosted later sales and waste for this purchase line, newest first.\nRequest this only after `recost_summary.expandable` is true on the line history page.\nWithout `costs.view`, `unit_cost` is omitted from `changes`.\n",
    "parameters": [
     {
      "name": "lineId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": "ID of the purchase line"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor.",
      "200": {
       "description": "Success",
       "content": {
        "application/json": {
         "schema": {
          "$ref": "#/components/schemas/AuditHistoryPage"
         }
        }
       }
      },
      "401": {
       "$ref": "#/components/responses/Unauthorized"
      },
      "403": {
       "$ref": "#/components/responses/Forbidden"
      },
      "404": {
       "$ref": "#/components/responses/NotFound"
      },
      "422": {
       "$ref": "#/components/responses/Unprocessable"
      },
      "429": {
       "$ref": "#/components/responses/RateLimited"
      }
     }
    ]
   }
  },
  "/v1/waste/{movementId}": {
   "patch": {
    "tags": [
     "Ingredients"
    ],
    "summary": "Amend a waste entry (PAN-156)",
    "operationId": "waste_amend",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "finance.amend"
    ],
    "description": "Corrects a waste entry (a `waste` stock movement id from the drill-down). A `quantity` change, or `revalue: true` (price at today's avg_unit_cost instead of the original cost), writes a reversal of the entry and a replacement on the same day: stock moves by the difference, avg_unit_cost is unchanged, and daily_financials waste_cost / net_profit move by (new - old) on the original day. The response's `entry.id` is the replacement; correct that id next time (the old one answers 409 `entry_already_corrected`). Only `note` / `waste_reason` changes are written in place (they carry no money). `reason` is required.",
    "parameters": [
     {
      "$ref": "#/components/parameters/MovementId"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/WasteAmend"
       },
       "example": {
        "quantity": "2000",
        "reason": "2,000,000 g was entered instead of 2,000 g"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Amended",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/WasteResult"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/StockConflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/waste/{movementId}/void": {
   "post": {
    "tags": [
     "Ingredients"
    ],
    "summary": "Void a waste entry (PAN-156)",
    "operationId": "waste_void",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "finance.amend"
    ],
    "description": "Writes a reversal of the waste entry (same cost, same day); the stock comes back and the day's waste_cost drops by the entry's amount. `reason` is required.",
    "parameters": [
     {
      "$ref": "#/components/parameters/MovementId"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/AmendReason"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Voided",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/WasteResult"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/waste/{movementId}/history": {
   "get": {
    "tags": [
     "Reports"
    ],
    "summary": "On-demand audit trail of a waste entry (PAN-221)",
    "operationId": "waste_history",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "reports.sales",
     "reports.cashflow",
     "expenses.view",
     "stock.view",
     "stock.correct",
     "stock.void",
     "finance.amend"
    ],
    "description": "Keyset-paginated correction history of one waste movement and its replacement chain,\nnewest first. Loaded only when the client requests it. Without `costs.view`, `unit_cost`\nand `amount` are omitted from `changes`. `actor_name` is never the literal Unknown.\n",
    "parameters": [
     {
      "name": "movementId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid"
      },
      "description": "ID of the waste stock movement"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor.",
      "200": {
       "description": "Success",
       "content": {
        "application/json": {
         "schema": {
          "$ref": "#/components/schemas/AuditHistoryPage"
         }
        }
       }
      },
      "401": {
       "$ref": "#/components/responses/Unauthorized"
      },
      "403": {
       "$ref": "#/components/responses/Forbidden"
      },
      "404": {
       "$ref": "#/components/responses/NotFound"
      },
      "422": {
       "$ref": "#/components/responses/Unprocessable"
      },
      "429": {
       "$ref": "#/components/responses/RateLimited"
      }
     }
    ]
   }
  },
  "/v1/finance/amendments": {
   "get": {
    "tags": [
     "Reports"
    ],
    "summary": "Correction history of a purchase line, waste entry, or expense (PAN-156/209)",
    "operationId": "fin_amendments",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "finance.amend"
    ],
    "description": "Every create/amend/void/correct of the entry, newest first, with who, when, before, after and reason.\nA waste entry id finds the whole chain (original and replacements). PAN-209: entity_id may also be an\nexpense id (returns audits for all its purchase lines); stock-in create always writes a create row so\nthe audit trail is never empty for a new entry; negative_override marks owner override voids/corrects.\n`changes` is added additively (PAN-221). Prefer the dedicated `/history` endpoints for new screens.\nCost keys without `costs.view` (PAN-201 / PAN-313): `unit_cost` and `avg_unit_cost` are omitted at every\ndepth, and `before` / `after` omit `amount`. `before` / `after.line_cost` is omitted on waste and\nstock_movement rows but kept on `purchase_line` rows (PAN-313), matching `ingredient_lines[].line_cost`\non `GET /v1/expenses` and `GET /v1/expenses/{expenseId}` (expenses.view; finance.amend requires\nexpenses.view). `expense_amount` is always kept. With `costs.view` every key is returned.\n",
    "parameters": [
     {
      "name": "entity_id",
      "in": "query",
      "required": true,
      "description": "Purchase line id, waste movement id, or expense id (PAN-209).",
      "schema": {
       "type": "string",
       "format": "uuid"
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "next_cursor"
         ],
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/FinanceAmendment"
           }
          },
          "next_cursor": {
           "type": "string",
           "nullable": true
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/expenses/{expenseId}/history": {
   "get": {
    "tags": [
     "Expenses"
    ],
    "summary": "On-demand amendment history of an expense (PAN-221)",
    "operationId": "exp_history",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "reports.sales",
     "reports.cashflow",
     "expenses.view",
     "stock.view",
     "stock.correct",
     "stock.void",
     "finance.amend"
    ],
    "description": "Every edit and delete of the expense, newest first, keyset-paginated. Works for a deleted\nexpense too. Another business's expense is 404. Loaded only when the client requests it;\nlist and detail payloads do not include it. `changes` stays the `{ field: { old, new } }`\nmap so today's app keeps working. The presented list is the additive `change_list` array\n(`field`, `before`, `after`). `actor_name` is never the literal Unknown; when nobody can\nbe named it is \"Nama tidak tersedia\".\n",
    "parameters": [
     {
      "name": "expenseId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the expense"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "required": [
          "data",
          "next_cursor"
         ],
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/ExpenseAmendment"
           }
          },
          "next_cursor": {
           "type": "string",
           "nullable": true
          }
         }
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/expenses/{expenseId}/ingredient-lines": {
   "post": {
    "tags": [
     "Expenses"
    ],
    "summary": "Add an ingredient line (adds stock)",
    "operationId": "exp_line_add",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "expenses.manage"
    ],
    "description": "Inserts the line, writes a `purchase` stock movement, updates ingredients.stock_quantity and the moving-average avg_unit_cost, all in one transaction.",
    "parameters": [
     {
      "name": "expenseId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the expense"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ExpenseLineWrite"
       },
       "example": {
        "ingredient_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
        "quantity": "500.000",
        "line_cost": "50000.00"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/ExpenseLine"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/stock-audits": {
   "get": {
    "tags": [
     "Stock Audits"
    ],
    "summary": "List stock audits",
    "operationId": "aud_list",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.view"
    ],
    "parameters": [
     {
      "name": "ingredient_id",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": ""
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": ""
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": ""
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/StockAudit"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Stock Audits"
    ],
    "summary": "Submit end-of-day count",
    "operationId": "aud_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.manage"
    ],
    "description": "Response is `{data:[StockAudit]}` (one per line). Writes an audit stock movement for each variance and sets stock_quantity to the counted value.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/AuditCreate"
       },
       "example": {
        "lines": [
         {
          "ingredient_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
          "counted_quantity": "930.000",
          "note": "EOD count"
         }
        ]
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/StockAudit"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/stock-audits/{auditId}": {
   "get": {
    "tags": [
     "Stock Audits"
    ],
    "summary": "Get stock audit",
    "operationId": "aud_get",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "stock.view"
    ],
    "parameters": [
     {
      "name": "auditId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the stock audit"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StockAudit"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/employees": {
   "get": {
    "tags": [
     "Employees & Shifts"
    ],
    "summary": "List employees",
    "operationId": "emp_list",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "payroll.shifts"
    ],
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Employee"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Employees & Shifts"
    ],
    "summary": "Create employee",
    "operationId": "emp_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "payroll.shifts"
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/EmployeeWrite"
       },
       "example": {
        "full_name": "Budi",
        "role": "Barista",
        "pay_type": "hourly",
        "hourly_rate": "20000.00",
        "hired_on": "2026-01-15"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Employee"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/employees/{employeeId}": {
   "get": {
    "tags": [
     "Employees & Shifts"
    ],
    "summary": "Get employee",
    "operationId": "emp_get",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "payroll.shifts"
    ],
    "parameters": [
     {
      "name": "employeeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the employee"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Employee"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Employees & Shifts"
    ],
    "summary": "Update employee",
    "operationId": "emp_patch",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "payroll.shifts"
    ],
    "parameters": [
     {
      "name": "employeeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the employee"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/EmployeeWrite"
       },
       "example": {
        "full_name": "Budi",
        "pay_type": "hourly",
        "hourly_rate": "22000.00"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Employee"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/employees/{employeeId}/shifts": {
   "get": {
    "tags": [
     "Employees & Shifts"
    ],
    "summary": "List shifts of an employee",
    "operationId": "shift_list",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "payroll.shifts"
    ],
    "parameters": [
     {
      "name": "employeeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the employee"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": ""
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": ""
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/Shift"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Employees & Shifts"
    ],
    "summary": "Start/record a shift",
    "operationId": "shift_create",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "payroll.shifts"
    ],
    "description": "Records a shift; omit `ended_at` while it is still open. Shifts of one employee never overlap: ranges are\n`[started_at, ended_at)` (touching shifts are fine) and an open shift runs on without end, so an employee\nhas at most one open shift and nothing can start after it. An overlap is 409 `shift_overlap`. Hours cannot\nland in a paid payroll period: a closed shift that overlaps the period of a paid run, or an open shift that\nstarts inside one, is 409 `shift_locked`. Periods are whole days in the timezone stored on the run when it was\ncreated (`PayrollRun.timezone`), the same bounds the run counts hours in.",
    "parameters": [
     {
      "name": "employeeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the employee"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ShiftCreate"
       },
       "example": {
        "started_at": "2026-10-04T01:00:00Z"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Shift"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "description": "`shift_overlap`: overlaps another shift of the employee. `shift_locked`: would put hours into a paid payroll period.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "shift_overlap",
          "message": "This shift overlaps another shift of the same employee",
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/shifts/{shiftId}": {
   "patch": {
    "tags": [
     "Employees & Shifts"
    ],
    "summary": "Edit or end a shift",
    "operationId": "shift_patch",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "payroll.shifts"
    ],
    "description": "Changes `started_at` and/or `ended_at` (at least one; an omitted field keeps its value). Ending an open\nshift is `{\"ended_at\": ...}`. A shift cannot be reopened: `ended_at: null` is a 422. `ended_at` must stay\nafter `started_at` (422). A shift in a paid payroll run (`locked_reason: payroll`) is 409 `shift_locked`;\nthe edited times run the same checks as create: 409 `shift_overlap` against the employee's other shifts\nand 409 `shift_locked` when they would put hours into a paid period.",
    "parameters": [
     {
      "name": "shiftId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the shift"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/ShiftUpdate"
       },
       "example": {
        "ended_at": "2026-10-04T09:00:00Z"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Shift"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "description": "`shift_locked`: the shift is in a paid payroll run, or the new times would put hours into a paid period. `shift_overlap`: the new times overlap another shift of the employee.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "shift_locked",
          "message": "This shift is in a paid payroll run and cannot be edited or deleted",
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Employees & Shifts"
    ],
    "summary": "Delete a shift",
    "operationId": "shift_delete",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "payroll.shifts"
    ],
    "description": "Hard-deletes a shift that is not in a paid payroll run. A locked shift (`locked_reason` is `payroll`) is 409 `shift_locked`. Draft runs are recalculated when they are paid, so the deleted hours drop out.",
    "parameters": [
     {
      "name": "shiftId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the shift"
     }
    ],
    "responses": {
     "204": {
      "description": "Deleted"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "description": "`shift_locked`: the shift is in a paid payroll run.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "shift_locked",
          "message": "This shift is in a paid payroll run and cannot be edited or deleted",
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/payroll-runs": {
   "get": {
    "tags": [
     "Payroll"
    ],
    "summary": "List payroll runs",
    "operationId": "pr_list",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "payroll.manage"
    ],
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/PayrollRun"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Payroll"
    ],
    "summary": "Create draft payroll run",
    "operationId": "pr_create",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "payroll.manage"
    ],
    "description": "Creates a draft run with one entry per employee whose active range (`hired_on` to `left_on`, both inclusive,\nnull = no bound) touches the period. Inactive employees are included only when they have a `left_on`\n(leavers are paid up to that day). Runs of one merchant never overlap: both period ends are inclusive days,\nso a period that shares any day with another run (draft or paid) is 409 `payroll_period_overlap`. Periods are\nfree-form; `frequency` is a label (default: the merchant's `payroll_frequency`), and\n`GET /v1/payroll-settings` returns a suggested `next_period`.\n\nThe merchant timezone is stored on the run (`timezone`) when it is created. The period edges (which shift\nhours count, and the paid-period shift lock) use that stored value, even if the merchant timezone changes\nlater.\n\nPay per line (PAN-70, MVP defaults; settings in `GET /v1/payroll-settings`):\n- Hourly staff: closed-shift hours overlapping the period (2 dp) x `hourly_rate`, 2 dp. Unchanged.\n- Monthly staff, `salary_proration: working_days`: `monthly_salary` x active working days in the run /\n  working days in that calendar month (`days_worked` on the line).\n- Monthly staff, `salary_proration: hourly`: `monthly_salary` / (working days in the month x\n  `standard_hours_per_day`) x closed-shift hours in the run (`hours_worked` on the line, the real hours).\n  Each calendar-month portion is capped at what working_days mode would pay for it (`monthly_salary` x the\n  employee's active working days in the portion / working days in that month): overtime is not modelled,\n  so extra hours (or a forgotten clock-out) never pay more than the days covered.\n- Working days are the merchant's `work_days` (default Mon-Sat; public holidays are not handled). Only days\n  inside the employee's active range count. A period that crosses months is split by calendar month, each\n  part uses its own month's working days, and the parts are summed.\n- A monthly line is rounded once to whole rupiah, half up.\n\nA draft is recalculated when it is paid, so later shift, employee and settings changes are picked up.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PayrollRunCreate"
       },
       "example": {
        "period_start": "2026-09-01",
        "period_end": "2026-09-30",
        "frequency": "monthly"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PayrollRun"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "description": "`payroll_period_overlap`: the period overlaps another payroll run of the merchant.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "payroll_period_overlap",
          "message": "This period overlaps another payroll run",
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/payroll-runs/preview": {
   "post": {
    "tags": [
     "Payroll"
    ],
    "summary": "Preview a payroll run (no writes)",
    "operationId": "pr_preview",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "payroll.manage"
    ],
    "description": "Takes the same body as `POST /v1/payroll-runs` and returns the lines a run created for that period would\nhave, without creating anything: no run, line or expense is written (the work runs in a read-only\ntransaction on one snapshot). The lines come from the same code as create and pay, so the rules are\nidentical: working_days or hourly proration, `hired_on` and `left_on` (both inclusive), inactive employees\nonly with a `left_on`, hourly staff from closed shifts, and the merchant timezone for the period edges.\nFigures are decimal strings with 2 decimals; `deductions` is always `0.00` on a new run.\n\nSame checks as create: a missing or invalid date, `period_end` before `period_start` or an unknown\n`frequency` is 422 `validation_failed`, and a period that shares a day with another run (draft or paid) is\n409 `payroll_period_overlap`. `open_shifts` is true when paying such a run would be refused with 409\n`open_shifts_in_period`, and `open_shifts_count` is how many open shifts cause that; the preview itself is not refused. Lines are ordered by employee name.\n`entries` is empty (totals `0.00`) when nobody was active.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PayrollRunCreate"
       },
       "example": {
        "period_start": "2026-10-01",
        "period_end": "2026-10-15"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PayrollPreview"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     }
    }
   }
  },
  "/v1/payroll-runs/{payrollRunId}": {
   "get": {
    "tags": [
     "Payroll"
    ],
    "summary": "Get payroll run with entries",
    "operationId": "pr_get",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "payroll.manage"
    ],
    "parameters": [
     {
      "name": "payrollRunId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the payroll run"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PayrollRun"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Payroll"
    ],
    "summary": "Delete draft payroll run",
    "operationId": "pr_delete",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "payroll.manage"
    ],
    "description": "Hard-deletes a draft run and its entries (PAN-72), freeing its period for a new run. A paid run is 409 `payroll_run_paid` and stays as it is. Another merchant's or a missing run is 404.",
    "parameters": [
     {
      "name": "payrollRunId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the payroll run"
     }
    ],
    "responses": {
     "204": {
      "description": "Deleted"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "description": "`payroll_run_paid`: the run is paid and cannot be deleted.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "payroll_run_paid",
          "message": "A paid payroll run cannot be deleted",
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/payroll-runs/{payrollRunId}/pay": {
   "post": {
    "tags": [
     "Payroll"
    ],
    "summary": "Pay run: creates one Manpower (opex) expense",
    "operationId": "pr_pay",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "payroll.manage"
    ],
    "description": "One transaction: the draft is first recalculated from the current shifts, employees and payroll settings (same rules as create), so the paid total is what gets locked; then run -> paid (paid_on set), one expense for the total net pay in the merchant's `Manpower` category (kind=opex), expense_id stored on the run. 409 `conflict` if already paid. 409 `open_shifts_in_period` while any shift of the merchant that started before the end of the period (run timezone) is still open: end it first; nothing changes. Once paid, the shifts in its period are locked for every employee (`locked_reason: payroll`, 409 `shift_locked` on edit or delete).",
    "parameters": [
     {
      "name": "payrollRunId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "ID of the payroll run"
     },
     {
      "$ref": "#/components/parameters/IdempotencyKey"
     }
    ],
    "requestBody": {
     "required": false,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PayrollPay"
       },
       "example": {}
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PayrollRun"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "description": "`conflict`: the run is already paid. `open_shifts_in_period`: a shift in the period is still open.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "open_shifts_in_period",
          "message": "A shift in this period is still open; end it before paying",
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/config": {
   "get": {
    "tags": [
     "Plans"
    ],
    "summary": "Public app configuration (payment provider)",
    "operationId": "config_get",
    "x-roles": [
     "public"
    ],
    "description": "PAN-114. No token. Tells the app which payment provider the server uses (`stub` while payments are a test double) and whether the Premium gate is on, so the app never needs a build flag. Never carries a secret.",
    "security": [],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PublicConfig"
        },
        "example": {
         "payment": {
          "provider": "stub"
         },
         "premium_required": true
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing": {
   "get": {
    "tags": [
     "Plans"
    ],
    "summary": "Billing status of the current business",
    "operationId": "billing_status",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-114. Any signed-in member, also while the business is unpaid (exempt from the Premium gate). `paid` says whether the business is actively paid (Lifetime, or Monthly inside its period); `payment_required` is true when the gate is closed right now (premium required and phase `paywall` or `unpaid`; it stays false during the 4 grace days), so ordinary calls answer 402. PAN-116 adds `phase` and the lapse fields. The same block is `payment` in `GET /v1/me`.",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BillingStatus"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     }
    }
   }
  },
  "/v1/billing/checkout": {
   "post": {
    "tags": [
     "Plans"
    ],
    "summary": "Start a (stub) checkout",
    "operationId": "billing_checkout",
    "x-roles": [
     "owner"
    ],
    "description": "PAN-114. Owner only; exempt from the Premium gate. Starts a checkout for `tier` (`MONTHLY` 249000 IDR a month or `LIFETIME` 1499000 IDR once; case-insensitive; `FREE` or unknown is 422 `plan_not_available`). Nothing is paid yet. Returns a `checkout_id` (valid 30 minutes) to confirm with `POST /v1/billing/checkout/confirm`. Only with the stub provider: any other provider is 501 `payment_provider_not_implemented`. A business that already has Lifetime gets 409. PAN-396: a business covered by its owner's active Premium (`covered_by` set) gets 409 `already_covered` with `details.covered_by`; while the owner's plan is lapsed the checkout stays open. Staff get 403 `permission_denied`.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/BillingCheckoutRequest"
       },
       "example": {
        "tier": "MONTHLY"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Created",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/StubCheckout"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "501": {
      "description": "The configured payment provider has no integration yet (`payment_provider_not_implemented`)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/checkout/confirm": {
   "post": {
    "tags": [
     "Plans"
    ],
    "summary": "Confirm a (stub) checkout, which marks the plan paid",
    "operationId": "billing_checkout_confirm",
    "x-roles": [
     "owner"
    ],
    "description": "PAN-114. Owner only; exempt from the Premium gate. Stub provider: confirming pays at once. MONTHLY is paid for 30 days (confirming while still paid adds 30 days to the current period end; after a lapse the 30 days start now); LIFETIME is set and never lapses. Confirming the same checkout again changes nothing (`already_confirmed: true`). 404 `checkout_not_found` (unknown, forged, or another business's), 410 `checkout_expired`, 422 `plan_not_available`, 409 for Lifetime already owned, 409 `already_covered` (PAN-396) when the owner's active Premium already covers the business, 501 `payment_provider_not_implemented`.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/BillingConfirmRequest"
       },
       "example": {
        "checkout_id": "stubco_..."
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/BillingConfirmed"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "410": {
      "$ref": "#/components/responses/Gone"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "501": {
      "description": "The configured payment provider has no integration yet (`payment_provider_not_implemented`)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    }
   }
  },
  "/v1/billing/add-ons": {
   "get": {
    "tags": [
     "Plans"
    ],
    "summary": "Add-ons per business (included, extra, in use, pending)",
    "operationId": "add_ons_get",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "PAN-117. Owner only; exempt from the Premium gate. Lists EVERY business the caller owns, with the add-on counts of each (counted per business): `businesses` (how many businesses the owner may own, `in_use` is the number owned) and `employees` (the employee cap of that business and its active employees). `pending` is a reduction waiting for the end of the paid period. `eligible` is false for a business that is not on an active Premium plan (`ineligible_reason`: `not_premium`, `lifetime`, `payment_lapsed`, `over_limit`). `over_limit` and `lapse` describe a business that was not kept. `cost` is the add-on cost per month now and once pending reductions land, with placeholder prices. Due reductions are settled before the answer.",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AddOnsOverview"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "post": {
    "tags": [
     "Plans"
    ],
    "summary": "Apply add-on changes (simulated payment)",
    "operationId": "add_ons_apply",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "PAN-117. Owner only; exempt from the Premium gate. `changes` are targets: the TOTAL extra quantity wanted for one business and add-on (0 removes it), not a delta. All changes apply together or none do. Increases apply now. Decreases are stored and take effect at the end of that business's paid period (see the quote). When a decrease would leave more businesses or employees than the new limit, send `keep` (`merchant_ids` and `employee_ids`, exactly as many as the quote asked for): without it 409 `ADDON_LIMIT` (`details[{kind, merchant_id, in_use, new_limit, required, provided, missing}]`); with a wrong list 422 `KEEP_LIST_INVALID` (same details). Asking for the current quantity cancels a pending reduction of that add-on. 422 `add_on_not_available` (unknown or not sold, or the business is not on an active Premium plan), 422 `add_on_quantity_invalid` (0 to `max_quantity`), 404 for a business the caller does not own. Nothing is charged (`charged: false`). The body is the same as `GET /v1/billing/add-ons` plus `charged` and `applied` (the quote that was applied).",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/AddOnsRequest"
       },
       "example": {
        "changes": [
         {
          "merchant_id": "CAFE42",
          "key": "extra_employee_accounts",
          "quantity": 2
         }
        ]
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Applied",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AddOnsApplied"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "409": {
      "description": "ADDON_LIMIT: the change leaves more than the new limit and no `keep` was sent.",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "ADDON_LIMIT",
          "message": "This change leaves more businesses or employees than the new limit. Choose what to keep.",
          "details": [
           {
            "kind": "employees",
            "merchant_id": "CAFE42",
            "in_use": 5,
            "new_limit": 4,
            "required": 4,
            "provided": 0,
            "missing": 4
           }
          ],
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "422": {
      "description": "validation_failed, add_on_not_available, add_on_quantity_invalid or KEEP_LIST_INVALID",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "KEEP_LIST_INVALID",
          "message": "Pick exactly what fits the new limits.",
          "details": [
           {
            "kind": "employees",
            "merchant_id": "CAFE42",
            "in_use": 5,
            "new_limit": 4,
            "required": 4,
            "provided": 3,
            "missing": 1
           }
          ],
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/billing/add-ons/quote": {
   "post": {
    "tags": [
     "Plans"
    ],
    "summary": "Review add-on changes before applying",
    "operationId": "add_ons_quote",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "PAN-117. Owner only; exempt from the Premium gate. Same body as the apply call (`keep` is ignored). Writes nothing. `rows` is the Change / Now / After table (`direction` increase, decrease or same; `effective` `now` or `period_end` with `effective_at`). `cost` is the change in add-on cost per month (placeholder prices). `needs_keep` lists what the owner must pick before a decrease can be applied: `kind` `businesses` (keep exactly `required` of the `candidates`, which are businesses) or `employees` (per `merchant_id`, keep exactly `required` of its active employees). Empty when nothing needs a decision.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/AddOnsRequest"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AddOnQuote"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "404": {
      "$ref": "#/components/responses/NotFound"
     },
     "422": {
      "description": "validation_failed, add_on_not_available or add_on_quantity_invalid",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/billing/add-ons/pending": {
   "delete": {
    "tags": [
     "Plans"
    ],
    "summary": "Cancel pending add-on reductions",
    "operationId": "add_ons_cancel_pending",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "PAN-117. Owner only; exempt from the Premium gate. Drops pending reductions so the current quantities stay. Optional query `merchant_id` (one business) and `key` (one add-on); with neither, every pending reduction of the caller's businesses is dropped. Idempotent. Returns the same body as `GET /v1/billing/add-ons`.",
    "parameters": [
     {
      "name": "merchant_id",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "pattern": "^[A-Z0-9]{3,16}$"
      }
     },
     {
      "name": "key",
      "in": "query",
      "required": false,
      "schema": {
       "type": "string",
       "enum": [
        "extra_businesses",
        "extra_employee_accounts"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/AddOnsOverview"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/plans": {
   "get": {
    "tags": [
     "Plans"
    ],
    "summary": "List plans and add-ons",
    "operationId": "plans_list",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "Any signed-in role. The same list for everyone. Names, limits, max quantities and prices come from server\nconfiguration. Every price is a placeholder (`placeholder: true`); `purchasable` stays false in this list and a plan\nis bought through `POST /v1/billing/checkout` (PAN-114, stub provider only). `default: true` marks the plan to preselect (Monthly).\n`add_ons_allowed` says whether add-ons apply to a plan. These limits are what the app shows; the limits the\nserver enforces today are unchanged. A saved selection never raises them.\n",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlanCatalog"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/merchants/me/plan-selection": {
   "post": {
    "tags": [
     "Plans"
    ],
    "summary": "Save the plan choice (stub, charges nothing)",
    "operationId": "plan_selection_set",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "Saves the owner's choice of Monthly or Lifetime and its add-ons. It REPLACES the whole saved choice and is\nrepeat-safe (the same body twice gives the same result, `selected_at` is kept). Nothing is charged:\n`merchant_tier` stays as it is, `limits.effective` does not change and the saved plan shows only in\n`limits.if_active`. `add_ons` omitted or `[]` means no add-ons. Lifetime takes no add-ons.\n`remind_later: true` sets `remind_after` to now + 7 days and keeps the choice. Sending only\n`{\"remind_later\": true}` (no tier) snoozes the saved choice without changing it; with nothing saved that is 422\n`validation_failed`. `tier` FREE or unknown is 422 `plan_not_available` (use DELETE to go back to Free).\nAdd-on errors: unknown key or an add-on the plan does not allow is 422 `add_on_not_available`\n(`details[{key, issue}]`); quantity below 1, not an integer, above `max_quantity` or a duplicate key is 422\n`add_on_quantity_invalid` (`details[{key, issue, max_quantity}]`). When a paid plan is already active the call\nis 409 `conflict`.\n",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PlanSelectionRequest"
       },
       "example": {
        "tier": "MONTHLY",
        "add_ons": [
         {
          "key": "extra_businesses",
          "quantity": 2
         }
        ],
        "remind_later": false
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlanSelectionResult"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "description": "validation_failed, plan_not_available, add_on_not_available or add_on_quantity_invalid",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "add_on_quantity_invalid",
          "message": "Pick a number from 1 to 10.",
          "details": [
           {
            "key": "extra_businesses",
            "issue": "quantity must be between 1 and 10",
            "max_quantity": 10
           }
          ],
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     }
    }
   },
   "delete": {
    "tags": [
     "Plans"
    ],
    "summary": "Clear the saved plan choice",
    "operationId": "plan_selection_clear",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "Removes the saved tier and its add-ons together (\"Switch to Free\"). Idempotent, so it is 200 when nothing is\nsaved. An active paid plan is not changed.\n",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PlanSelectionCleared"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/merchants/me/onboarding": {
   "get": {
    "tags": [
     "Onboarding"
    ],
    "summary": "Get onboarding state",
    "operationId": "onboarding_get",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "Exempt from the Premium gate (setup then pay; never 402). One row per merchant, created with the merchant. Any device resumes at `current_step` with the saved `answers`. Merchants that existed before PAN-78 and already had a menu, an order or an ingredient are `completed`. `plan_state` is derived from the merchant tier and subscription; `plan_selection` is the saved plan choice (see POST /v1/merchants/me/plan-selection) or null.",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Onboarding"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Onboarding"
    ],
    "summary": "Save an onboarding step and answers",
    "operationId": "onboarding_patch",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "Exempt from the Premium gate (setup then pay; never 402).\nOptimistic locking: send the `version` you loaded; success returns the new state with `version` + 1. Send\n`current_step`, `answers` or both. Answers merge per key; `null` is rejected. `current_step` `done` needs the\nanswers applied (`applied_at` set) and, in the `full` flow, a `selected_tier` answer; otherwise 409\n`onboarding_not_ready`. The `Idempotency-Key` header is required: the same key with the same body replays the\nstored response, the same key with a different body is 409 `conflict`. Failed requests are not stored.\n`selected_add_ons` is validated against the add-on catalog only (key, integer quantity from 1 to the catalog\nmaximum, no duplicates). Nothing is charged or enforced by a selection.\n",
    "parameters": [
     {
      "$ref": "#/components/parameters/RequiredIdempotencyKey"
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/OnboardingUpdate"
       },
       "example": {
        "version": 4,
        "current_step": "stock",
        "answers": {
         "team_size": "small"
        }
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Onboarding"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "409": {
      "description": "onboarding_version_conflict, onboarding_already_completed, onboarding_not_ready or conflict (Idempotency-Key reused with a different body)",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "error": {
          "code": "onboarding_version_conflict",
          "message": "Onboarding changed since you loaded it; reload and retry",
          "details": [
           {
            "field": "version",
            "issue": "stale",
            "version": 5,
            "current_step": "stock"
           }
          ],
          "request_id": "req_01HX0000"
         }
        }
       }
      }
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/merchants/me/onboarding/apply": {
   "post": {
    "tags": [
     "Onboarding"
    ],
    "summary": "Apply the onboarding answers",
    "operationId": "onboarding_apply",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "Exempt from the Premium gate (setup then pay; never 402).\nNo body. Writes `business_name` and `timezone` to the merchant, writes the payroll frequency and proration when\n`payroll_enabled` is true (defaults monthly and working_days), and creates the starter categories as menus once:\nonly when the merchant has no menus and `categories_seeded_at` is empty. Starter names per `business_type` are\nconfiguration (food_drink: Food, Drinks, Snacks; retail: Products, Accessories, Other; services: Services,\nPackages, Add-ons; mix or unset: Food, Drinks, Other). Re-running apply re-sends name, timezone and payroll but\nnever reseeds (`categories_created` 0). Apply does not change `version`; `applied_at` keeps its first value.\nThe `Idempotency-Key` header is required and replays the stored response. After `complete`, apply is 409\n`onboarding_already_completed` unless it was applied before, in which case it replays with 0 and writes nothing.\nThe app calls apply after the payroll step in the `second_business` flow.\nPAN-342 B3: a `business_name` that changes the name updates `GET /v1/me/merchants` the same way as\n`PATCH /v1/merchants/me` (copied after commit, background retry on failure; apply still succeeds).\n",
    "parameters": [
     {
      "$ref": "#/components/parameters/RequiredIdempotencyKey"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/OnboardingApplyResult"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     }
    }
   }
  },
  "/v1/merchants/me/onboarding/complete": {
   "post": {
    "tags": [
     "Onboarding"
    ],
    "summary": "Complete onboarding",
    "operationId": "onboarding_complete",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "settings.manage"
    ],
    "description": "Exempt from the Premium gate (setup then pay; never 402); completing onboarding does not open the gate for other routes. No body. Sets `status` completed and `completed_at`. Needs `current_step` `done`, otherwise 409 `onboarding_not_ready`. Repeating it returns the completed state unchanged.",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Onboarding"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     },
     "409": {
      "$ref": "#/components/responses/Conflict"
     }
    }
   }
  },
  "/v1/payroll-settings": {
   "get": {
    "tags": [
     "Payroll"
    ],
    "summary": "Get payroll settings",
    "operationId": "pr_settings_get",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "payroll.manage"
    ],
    "description": "The merchant's payroll settings (PAN-70) and a suggested period for the next run.",
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PayrollSettings"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "patch": {
    "tags": [
     "Payroll"
    ],
    "summary": "Update payroll settings",
    "operationId": "pr_settings_patch",
    "x-roles": [
     "owner"
    ],
    "x-permissions": [
     "payroll.manage"
    ],
    "description": "Send at least one field; omitted fields keep their value and null is not accepted. Changes apply to new runs and to drafts when they are paid (pay recalculates); paid runs never change.",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/PayrollSettingsUpdate"
       },
       "example": {
        "salary_proration": "hourly",
        "standard_hours_per_day": "7.5"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/PayrollSettings"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/reports/cashflow": {
   "get": {
    "tags": [
     "Reports"
    ],
    "summary": "Cashflow report (backed by the daily_financials summary)",
    "operationId": "rep_cashflow",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "reports.cashflow"
    ],
    "description": "Days are bucketed in the merchant timezone. One response carries the period totals: cash_in (completed payments minus completed refunds), cash_out (all expenses), net_cash (cash_in minus cash_out), and gross_profit (net sales minus ingredient cost of goods sold). PAN-391 Net definition: gross_sales = total_sales + revenue charges (by the kind each order took, close day); sales_refunds = refunds minus their tax, collected_for_others and Unclassified charge parts (paid day); net_sales = gross_sales - sales_refunds. So revenue charges count as sales and pass-through or Unclassified charges never do; refunds stays the full refund (cash). Before PAN-391 net_sales was total_sales minus refunds, so past periods with charges show new net_sales, gross_profit and net_profit. Ingredient COGS (cost_of_sales) is the cost of sale stock movements at their unit_cost, i.e. the ingredient cost of sold items (PAN-130); expenses, including ingredient purchases, never feed it. gross_profit = net_sales - cost_of_sales. waste_cost is the cost of waste stock movements (write-offs) at their unit_cost, reported on its own line; operating_expenses is every expense minus the part covered by ingredient purchase lines (PAN-143), so a manual expense lowers net_profit but never gross_profit; net_profit = gross_profit - operating_expenses - waste_cost. Callers without costs.view get no cost_of_sales, gross_profit, waste_cost or net_profit. expenses_by_category sums expenses in the same period. low_stock lists ingredients whose stock_quantity is at or below min_quantity. has_low_stock is true when that list is not empty. rows and totals are read from the daily_financials summary table (one row per merchant and merchant-local business day), which database triggers keep current in the same transaction as every money write by adding the change of that write to its day (PAN-153; no full-day recompute): order close, item served (sale movement), waste, expense create, expense ingredient line add, payroll pay, ingredient delete (cascaded sale/waste movements) and a timezone change (full rebuild). The day is the business date of the event (order close time, payment paid_at, movement occurred_at in the merchant timezone; expense incurred_on), so a back-dated expense updates its own day. v_daily_cashflow keeps the same formulas and is used only to rebuild or repair the summary. previous is the period of the same number of days that ends the day before from, grouped the same way, with its own totals and rows, so the Dashboard needs one call for this-period and previous-period figures. When from or to is omitted, previous is computed from the resolved from/to in the response. Clients that do not read previous can ignore it.",
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "Start date (inclusive, merchant tz)."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "End date (inclusive)."
     },
     {
      "name": "group_by",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "day (default) | week | month"
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/CashflowReport"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/reports/sales": {
   "get": {
    "tags": [
     "Reports"
    ],
    "summary": "Ranked sales by menu item",
    "operationId": "rep_sales",
    "x-roles": [
     "owner",
     "manager"
    ],
    "x-permissions": [
     "reports.sales"
    ],
    "description": "One page of menu items sold on closed orders in the period, excluding cancelled lines. The day is COALESCE(closed_at, ordered_at) in the merchant timezone. from and to are inclusive; omit either side to leave it open.\ntype is required. It filters the ranking and sets the order, highest first, then item name and id:\nmost_items_sold orders by quantity sold. most_sales orders by line revenue (quantity * unit price) before refunds. most_refunds orders by the item's share of completed refunds on those orders. most_net_sales orders by net_sales (PAN-391 Net: item sales after refunds plus revenue charges after their refund share). most_cost_of_sales orders by ingredient cost. most_gross_profit orders by net_sales minus ingredient cost. most_item_sales_after_refunds orders by item_sales_after_refunds (no revenue charges). most_gross_profit_after_refunds orders by item_sales_after_refunds minus ingredient cost; amount is that value (gross_profit stays net_sales minus cost).\nFor every item, sold_count is the quantity sold. PAN-159: net_sales is gross sales (line revenue) minus that item's share of completed refunds. PAN-388: only the menu-price part of a refund counts, i.e. the refund times the order's item total divided by item total plus bill charges, then split across the order's lines by their share of line revenue, so a full refund of a bill with charges and tax brings the item to 0, never below. Until PAN-391 PR2 this is Item sales after refunds, not the bill-level Net sales. cost_of_sales is the sale stock movements of those lines at unit_cost. Waste is not an item cost and is never subtracted. gross_profit is net_sales minus cost_of_sales. amount is the value used to order the page.\nPermission rule: without costs.view the item rows have no gross_profit or cost_of_sales keys, totals has no cost_of_sales, operating_expenses or waste_cost keys, and type=most_gross_profit, type=most_gross_profit_after_refunds or type=most_cost_of_sales is 403 permission_denied (error.permission costs.view). most_net_sales, most_item_sales_after_refunds and the other types are open to any reports.sales caller.\nlimit is the page size (default 10, maximum 100). Pass next_cursor back as cursor, with the same type, from and to, to read the next page. A cursor from a different type or date range is 422. next_cursor is null on the last page.",
    "parameters": [
     {
      "name": "type",
      "in": "query",
      "required": true,
      "schema": {
       "type": "string",
       "enum": [
        "most_items_sold",
        "most_sales",
        "most_refunds",
        "most_net_sales",
        "most_cost_of_sales",
        "most_gross_profit",
        "most_item_sales_after_refunds",
        "most_gross_profit_after_refunds"
       ]
      },
      "description": "Ranking filter. Also the order of the page, highest first."
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "Start date (inclusive, merchant timezone). Omit for no start bound."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "End date (inclusive, merchant timezone). Omit for no end bound."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 10
      },
      "description": "Page size, 1-100 (default 10)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor. Valid only with the same type, from and to."
     }
    ],
    "responses": {
     "200": {
      "description": "Success",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/SalesReport"
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/kitchen/queue": {
   "get": {
    "tags": [
     "Kitchen"
    ],
    "summary": "Read-only queue of open order rounds",
    "operationId": "kitchen_queue",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "orders.queue"
    ],
    "description": "VIEW-ONLY. The only data endpoint the `kitchen` role may call (besides the session endpoints under /v1/auth, GET /v1/me/merchants and the FCM device endpoints under /v1/devices/fcm). Shows the caller's merchant open orders as rounds that still have preparing items, with order_no, table label and age, oldest first. Placed items are not on the queue until the waiter confirms the round. There are no confirm/start/cancel endpoints and no ticket status. Items are ticked through PATCH /v1/orders/{orderId}/items/{orderItemId}: `ready` by owner, manager and kitchen, `served` or cancelled by owner, manager and cashier (PAN-87). Each line carries ready_at, ready_by_name, served_at and served_by_name; served lines stay on a round that still has a preparing line, and the round drops off the queue when every line is served or cancelled. Each round has line_count (preparing and served lines), ready_count (ready or served) and served_count. Poll every few seconds (or on app focus).\n\nConditional polling (PAN-42): every 200 and 304 carries a strong `ETag` and `Cache-Control: private, no-cache`. The ETag is a full-queue watermark: a hash of every round of the merchant's queue (all pages: order, order_no, table_label, round_no, round_added_at and each item's name, quantity, note, status, short fields and ticks, in queue order), combined with this request's limit and cursor. age_seconds is not part of it, so an idle queue keeps its ETag. Send the last ETag back in `If-None-Match`; while nothing on the queue has changed, any page (any limit/cursor) answers 304 Not Modified with no body. A confirm, serve, cancel, edit, new confirmed round, order close or cancel changes the ETag of every page and the next poll gets 200 with the new body and ETag. If-None-Match uses weak comparison: a W/ prefix is ignored, a comma-separated list and `*` are accepted. After a 304, recompute ages from round_added_at.",
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 100,
       "default": 25
      },
      "description": "Page size, 1-100 (default 25)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Opaque cursor from the previous page next_cursor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "required": false,
      "schema": {
       "type": "string",
       "example": "\"kq1-3f2a9c0d1b7e4a5f8c6d2e1f0a9b8c7d\""
      },
      "description": "ETag from a previous response of this page. A match returns 304 Not Modified."
     }
    ],
    "responses": {
     "304": {
      "description": "Not Modified. The queue has not changed since the ETag in If-None-Match. No body.",
      "headers": {
       "ETag": {
        "description": "Current strong ETag (same value the client sent).",
        "schema": {
         "type": "string"
        }
       },
       "Cache-Control": {
        "schema": {
         "type": "string",
         "example": "private, no-cache"
        }
       }
      }
     },
     "200": {
      "description": "Success",
      "headers": {
       "ETag": {
        "description": "Strong ETag of this page, built from the full-queue watermark plus limit and cursor.",
        "schema": {
         "type": "string",
         "example": "\"kq1-3f2a9c0d1b7e4a5f8c6d2e1f0a9b8c7d\""
        }
       },
       "Cache-Control": {
        "schema": {
         "type": "string",
         "example": "private, no-cache"
        }
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/QueueRound"
           }
          },
          "next_cursor": {
           "type": "string",
           "example": "opaque",
           "nullable": true
          }
         },
         "required": [
          "data"
         ]
        }
       }
      }
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  },
  "/v1/devices/fcm": {
   "post": {
    "tags": [
     "Kitchen"
    ],
    "summary": "Register this device's FCM token for kitchen queue nudges",
    "operationId": "device_fcm_register",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "PAN-45. Upserts the Firebase Cloud Messaging registration token for the caller's current merchant and membership (unique on token: registering a token that is already stored moves it to this membership). Call it after sign-in, after switching merchant and whenever the FCM SDK reports a new token. Platform is web for now. The token is never echoed or logged. At most 10 tokens are kept per membership (oldest pruned).\n\nWhen the merchant's kitchen queue changes (a round is confirmed to preparing, a queued item is served or cancelled, or an order with queued items is closed or cancelled) the API sends a data-only FCM HTTP v1 message, with no notification title or body, to every registered token of the merchant's active members whose effective permissions include orders.queue (PAN-319): the owner, the manager / cashier / kitchen starters, and custom roles that hold orders.queue; revoked (inactive) members get nothing. Tokens are read from the merchant's shard. data = {\"type\": \"kitchen_queue_changed\", \"merchant_id\": \"<business_code>\"}. Bursts are coalesced per merchant. On receipt, re-poll GET /v1/kitchen/queue (with If-None-Match). The queue itself is never in the payload. Tokens FCM reports as UNREGISTERED are deleted. push_active is false while push is not configured on the server, in which case registration still works but nothing is sent (keep polling).",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/FcmDeviceRegisterRequest"
       }
      }
     }
    },
    "responses": {
     "200": {
      "description": "Registered (created or updated).",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/FcmDevice"
        }
       }
      }
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   },
   "delete": {
    "tags": [
     "Kitchen"
    ],
    "summary": "Unregister an FCM token (call on sign-out)",
    "operationId": "device_fcm_unregister",
    "x-roles": [
     "owner",
     "manager",
     "cashier",
     "kitchen"
    ],
    "x-permissions": [
     "any"
    ],
    "description": "Deletes the token if it belongs to any membership of the caller's account. Idempotent; an unknown token also returns 204. Call it before discarding the session on sign-out (the access token must still be valid).",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/FcmDeviceTokenRequest"
       }
      }
     }
    },
    "responses": {
     "204": {
      "description": "No content"
     },
     "400": {
      "$ref": "#/components/responses/BadRequest"
     },
     "401": {
      "$ref": "#/components/responses/Unauthorized"
     },
     "403": {
      "$ref": "#/components/responses/Forbidden"
     },
     "422": {
      "$ref": "#/components/responses/Unprocessable"
     },
     "429": {
      "$ref": "#/components/responses/RateLimited"
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearerAuth": {
    "type": "http",
    "scheme": "bearer",
    "bearerFormat": "JWT",
    "description": "Access token from a session response. PAN-277 - it carries `sid`, the refresh-token session id; a revoked session (or a token without `sid`) is 401 `unauthorized` on every route behind this scheme."
   }
  },
  "parameters": {
   "LineId": {
    "name": "lineId",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid"
    },
    "description": "ID of the expense ingredient (purchase) line"
   },
   "MovementId": {
    "name": "movementId",
    "in": "path",
    "required": true,
    "schema": {
     "type": "string",
     "format": "uuid"
    },
    "description": "ID of the waste stock movement"
   },
   "Limit": {
    "name": "limit",
    "in": "query",
    "schema": {
     "type": "integer",
     "minimum": 1,
     "maximum": 100,
     "default": 25
    },
    "description": "Page size, 1-100 (default 25)."
   },
   "Cursor": {
    "name": "cursor",
    "in": "query",
    "schema": {
     "type": "string"
    },
    "description": "Opaque cursor from the previous page's next_cursor."
   },
   "IdempotencyKey": {
    "name": "Idempotency-Key",
    "in": "header",
    "required": false,
    "schema": {
     "type": "string",
     "maxLength": 128
    },
    "description": "Optional. Not enforced yet; the server accepts the header but does not deduplicate requests. Planned behaviour is that repeating the same key with the same body returns the original result."
   },
   "RequiredIdempotencyKey": {
    "name": "Idempotency-Key",
    "in": "header",
    "required": true,
    "schema": {
     "type": "string",
     "minLength": 1,
     "maxLength": 255
    },
    "description": "Required (PAN-78). 1 to 255 printable ASCII characters, scoped per merchant and endpoint. Missing or invalid is 400 bad_request. The same key with the same request replays the first 2xx response; the same key with a different body is 409 conflict."
   }
  },
  "responses": {
   "BadRequest": {
    "description": "Malformed request",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "bad_request",
        "message": "Invalid JSON body",
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   },
   "Unauthorized": {
    "description": "Missing, expired or invalid access token (`unauthorized`; the message says which). Also `unauthorized` \"Membership is no longer active\" once a member is deactivated or removed, and (PAN-277) `unauthorized` \"Session has been signed out\" when the token's session (`sid`) was revoked or the token has no `sid`. Checking the session needs the directory: when it cannot be reached the answer is 503 `directory_unavailable`. The refresh endpoint adds `refresh_reuse_detected` for a used or revoked refresh token, which is what an ended session looks like (there is no `session_revoked` code).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "unauthorized",
        "message": "Access token expired",
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   },
   "Forbidden": {
    "description": "The caller's role lacks a permission (`permission_denied`, with the key in `error.permission`) or the tier does not allow this.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "permission_denied",
        "message": "Your role does not have the orders.create permission",
        "permission": "orders.create",
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   },
   "NotFound": {
    "description": "Not found (also returned for other merchants' resources)",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "not_found",
        "message": "Resource not found",
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   },
   "StockConflict": {
    "description": "State conflict. `insufficient_stock` (PAN-170): the change would take the ingredient below zero;\n`details` has `ingredient_id`, `available` and `required` (stock unit). Nothing is written.\nPAN-218: when the caller holds `stock.override`, `details` also includes `can_override: true` and\n`resulting_stock` (what on-hand would become). Retry with `confirm_negative_stock: true` to apply.\n",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "insufficient_stock",
        "message": "Not enough stock: this change would take the ingredient below zero",
        "details": {
         "ingredient_id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
         "available": "2.000",
         "required": "10.000",
         "can_override": true,
         "resulting_stock": "-8.000"
        }
       }
      }
     }
    }
   },
   "Conflict": {
    "description": "State conflict",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "conflict",
        "message": "Order is not open",
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   },
   "CategoryExists": {
    "description": "PAN-128: a category (menu) with this name already exists in the merchant, compared case-insensitively. `error.existing` is that category.",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "category_exists",
        "message": "A category with this name already exists",
        "details": [
         {
          "field": "menu_name",
          "issue": "taken"
         }
        ],
        "existing": {
         "id": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
         "name": "Food"
        },
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   },
   "ShardNotMapped": {
    "description": "Directory routing is on but this business has no placement in the in-memory merchant→shard map (or the shard pool could not be opened). Feature handlers never fall back to the bootstrap/default database. Structured server logs include `business_code` and `route`. Not used when `Shards` is nil (single-DB). PR4: also returned by the public staff routes (`/v1/auth/employee/*`) and `/v1/auth/refresh` when the business named by the employee ID / link code is placed but its shard cannot be reached (an unknown business is answered like an unknown ID or link).",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "shard_not_mapped",
        "message": "This business is not assigned to a database shard",
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   },
   "Gone": {
    "description": "Link no longer valid (INVITE_EXPIRED, INVITE_USED, INVITE_REVOKED)",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "INVITE_EXPIRED",
        "message": "Invitation expired: links are valid for 30 minutes after creation",
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   },
   "StorageCapExceeded": {
    "description": "Payload/storage too large (e.g. storage_cap_exceeded, 1 MiB per-image limit)",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "storage_cap_exceeded",
        "message": "Storage cap exceeded: FREE tier allows 104857600 bytes (100 MiB)",
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   },
   "Unprocessable": {
    "description": "Validation failed",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "validation_failed",
        "message": "quantity must be > 0",
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   },
   "RateLimited": {
    "description": "Too many requests",
    "content": {
     "application/json": {
      "schema": {
       "$ref": "#/components/schemas/Error"
      },
      "example": {
       "error": {
        "code": "rate_limited",
        "message": "Retry after 5s",
        "request_id": "req_01HX0000"
       }
      }
     }
    }
   }
  },
  "schemas": {
   "AmendReason": {
    "type": "object",
    "required": [
     "reason"
    ],
    "properties": {
     "reason": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "description": "Why the entry is corrected (required, kept in the audit trail)."
     }
    }
   },
   "VoidPurchaseLineBody": {
    "type": "object",
    "required": [
     "reason"
    ],
    "properties": {
     "reason": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200,
      "description": "Why the line is voided (required, kept in the audit trail)."
     },
     "confirm_negative_stock": {
      "type": "boolean",
      "description": "PAN-218. When stock.override is held and reversing the purchase would take stock below zero,\nset true to apply anyway (stock may go negative). Without stock.override this flag is ignored.\nOmit or false → 409 insufficient_stock with can_override and resulting_stock.\n"
     }
    }
   },
   "PurchaseLineAmend": {
    "type": "object",
    "required": [
     "reason"
    ],
    "properties": {
     "ingredient_id": {
      "type": "string",
      "format": "uuid"
     },
     "quantity": {
      "type": "string",
      "description": "Entered quantity, in `unit` (else the line's unit)."
     },
     "unit": {
      "type": "string",
      "description": "Optional line unit (PAN-95); \"\" means the ingredient's stock unit."
     },
     "line_cost": {
      "type": "string"
     },
     "unit_cost": {
      "type": "string",
      "description": "Alternative to line_cost."
     },
     "incurred_on": {
      "type": "string",
      "format": "date"
     },
     "note": {
      "type": "string",
      "nullable": true
     },
     "reason": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
     },
     "confirm_unusual": {
      "type": "boolean",
      "description": "PAN-202. Save anyway after unusual_value 422."
     }
    }
   },
   "IngredientStock": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "ingredient_name": {
      "type": "string"
     },
     "unit": {
      "type": "string"
     },
     "stock_quantity": {
      "type": "string"
     },
     "avg_unit_cost": {
      "type": "string",
      "description": "Omitted when the caller lacks costs.view (PAN-201)."
     }
    }
   },
   "AuditChange": {
    "type": "object",
    "required": [
     "field"
    ],
    "properties": {
     "field": {
      "type": "string",
      "description": "Canonical field name (quantity, line_cost, stock, amount, note, and so on)."
     },
     "before": {
      "description": "Value before the change. Null when the field was added."
     },
     "after": {
      "description": "Value after the change. Null when the field was removed."
     },
     "unit": {
      "type": "string",
      "description": "For quantity, change_qty and stock, the ingredient stock unit (g, kg, ml, and so on). For line_quantity, the unit the owner typed (line_unit). Never use line_unit as the unit of quantity."
     }
    }
   },
   "RecostSummary": {
    "type": "object",
    "required": [
     "count",
     "expandable"
    ],
    "properties": {
     "count": {
      "type": "integer",
      "minimum": 0
     },
     "expandable": {
      "type": "boolean"
     }
    }
   },
   "AuditHistoryItem": {
    "type": "object",
    "required": [
     "id",
     "action",
     "actor_name",
     "created_at",
     "changes"
    ],
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "entity_type": {
      "type": "string",
      "enum": [
       "purchase_line",
       "waste",
       "stock_movement"
      ]
     },
     "entity_id": {
      "type": "string",
      "format": "uuid"
     },
     "action": {
      "type": "string"
     },
     "actor_name": {
      "type": "string"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "reason": {
      "type": "string",
      "nullable": true,
      "description": "Omitted or null for the synthetic created reason."
     },
     "unusual": {
      "type": "boolean"
     },
     "negative_override": {
      "type": "boolean"
     },
     "changes": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/AuditChange"
      }
     }
    }
   },
   "AuditHistoryPage": {
    "type": "object",
    "required": [
     "data",
     "next_cursor"
    ],
    "properties": {
     "data": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/AuditHistoryItem"
      }
     },
     "recost_summary": {
      "$ref": "#/components/schemas/RecostSummary"
     },
     "next_cursor": {
      "type": "string",
      "nullable": true
     }
    }
   },
   "FinanceAmendment": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "entity_type": {
      "type": "string",
      "enum": [
       "purchase_line",
       "waste",
       "stock_movement"
      ]
     },
     "entity_id": {
      "type": "string",
      "format": "uuid"
     },
     "replacement_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true
     },
     "action": {
      "type": "string",
      "enum": [
       "amend",
       "void",
       "correct",
       "create",
       "corrected",
       "recosted"
      ]
     },
     "before": {
      "type": "object",
      "additionalProperties": true,
      "description": "Snapshot before the change. Callers without costs.view lose unit_cost, avg_unit_cost and amount keys (PAN-201), and line_cost except on purchase_line rows, which keep it on GET /v1/finance/amendments (PAN-313) and the purchase-line amend / void / correct responses (PAN-318)."
     },
     "after": {
      "type": "object",
      "additionalProperties": true,
      "description": "Snapshot after the change. Same costs.view omit rules as before (PAN-201)."
     },
     "reason": {
      "type": "string"
     },
     "unusual": {
      "type": "boolean",
      "description": "True when Save anyway (confirm_unusual) was used (PAN-202)."
     },
     "negative_override": {
      "type": "boolean",
      "description": "PAN-209. True when after.negative_override was set (owner stock.override void/correct)."
     },
     "actor_name": {
      "type": "string",
      "description": "PAN-322 / PAN-336 / PAN-221. Who made this change: the shard staff login name, else the directory account display name, else its email; never the creator, never another business's staff or owner, never a payroll employee. Copied at write time; a row stored blank or as the literal Unknown is resolved from its actor id when read. When nobody can be named the value is Nama tidak tersedia (never the literal Unknown)."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "changes": {
      "type": "array",
      "description": "PAN-221. Presented field changes, additive on GET /v1/finance/amendments. Flag-only keys such as original_quantity and corrected are omitted.",
      "items": {
       "$ref": "#/components/schemas/AuditChange"
      }
     }
    }
   },
   "PurchaseLineCorrect": {
    "type": "object",
    "required": [
     "reason"
    ],
    "properties": {
     "category_id": {
      "type": "string",
      "format": "uuid"
     },
     "amount": {
      "type": "string"
     },
     "incurred_on": {
      "type": "string",
      "format": "date"
     },
     "supplier": {
      "type": "string"
     },
     "note": {
      "type": "string"
     },
     "ingredient_id": {
      "type": "string",
      "format": "uuid"
     },
     "quantity": {
      "type": "string"
     },
     "unit": {
      "type": "string"
     },
     "line_cost": {
      "type": "string"
     },
     "reason": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
     },
     "confirm_unusual": {
      "type": "boolean"
     },
     "confirm_negative_stock": {
      "type": "boolean",
      "description": "PAN-218/222. With stock.override, allow the in-place stock delta (new−old) to leave\non-hand below zero. Without override the flag is ignored (409 insufficient_stock).\n"
     }
    }
   },
   "CorrectPurchaseResult": {
    "type": "object",
    "required": [
     "line_id",
     "expense_id",
     "amendment"
    ],
    "properties": {
     "line_id": {
      "type": "string",
      "format": "uuid",
      "description": "Same purchase line id (in-place; PAN-222)."
     },
     "expense_id": {
      "type": "string",
      "format": "uuid"
     },
     "expense_amount": {
      "type": "string"
     },
     "incurred_on": {
      "type": "string",
      "format": "date",
      "description": "Unchanged from the original line."
     },
     "line": {
      "$ref": "#/components/schemas/ExpenseLine"
     },
     "ingredients": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/IngredientStock"
      }
     },
     "amendment": {
      "$ref": "#/components/schemas/FinanceAmendment"
     },
     "recosted_count": {
      "type": "integer",
      "description": "Sale/waste movements whose unit_cost was rewritten until the next purchase."
     }
    }
   },
   "PurchaseLineResult": {
    "type": "object",
    "properties": {
     "line_id": {
      "type": "string",
      "format": "uuid"
     },
     "expense_id": {
      "type": "string",
      "format": "uuid"
     },
     "voided": {
      "type": "boolean"
     },
     "expense_amount": {
      "type": "string"
     },
     "expense_deleted": {
      "type": "boolean",
      "description": "PAN-219: always false — void never soft-deletes the parent expense."
     },
     "incurred_on": {
      "type": "string",
      "format": "date"
     },
     "line": {
      "allOf": [
       {
        "$ref": "#/components/schemas/ExpenseLine"
       }
      ],
      "nullable": true
     },
     "ingredients": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/IngredientStock"
      }
     },
     "amendment": {
      "$ref": "#/components/schemas/FinanceAmendment"
     }
    }
   },
   "WasteAmend": {
    "type": "object",
    "required": [
     "reason"
    ],
    "properties": {
     "quantity": {
      "type": "string",
      "description": "New wasted quantity in the stock unit (> 0; void to remove)."
     },
     "waste_reason": {
      "type": "string",
      "nullable": true,
      "maxLength": 64
     },
     "note": {
      "type": "string",
      "nullable": true,
      "maxLength": 2000
     },
     "revalue": {
      "type": "boolean",
      "default": false
     },
     "reason": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
     }
    }
   },
   "WasteEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "ingredient_id": {
      "type": "string",
      "format": "uuid"
     },
     "quantity": {
      "type": "string"
     },
     "unit_cost": {
      "type": "string",
      "description": "Omitted when the caller lacks costs.view (PAN-201)."
     },
     "amount": {
      "type": "string",
      "description": "Waste value (quantity x unit_cost). Omitted when the caller lacks costs.view (PAN-201)."
     },
     "waste_reason": {
      "type": "string",
      "nullable": true
     },
     "note": {
      "type": "string",
      "nullable": true
     },
     "created_by_name": {
      "type": "string",
      "nullable": true
     },
     "created_by_user_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true,
      "description": "PAN-224 acting account id; null on legacy rows."
     },
     "occurred_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "WasteResult": {
    "type": "object",
    "properties": {
     "entry_id": {
      "type": "string",
      "format": "uuid",
      "description": "The entry that was corrected."
     },
     "voided": {
      "type": "boolean"
     },
     "entry": {
      "allOf": [
       {
        "$ref": "#/components/schemas/WasteEntry"
       }
      ],
      "nullable": true,
      "description": "The live entry after the change (its id is the replacement); null after a void."
     },
     "ingredient": {
      "$ref": "#/components/schemas/IngredientStock"
     },
     "amendment": {
      "$ref": "#/components/schemas/FinanceAmendment"
     }
    }
   },
   "DayEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "kind": {
      "type": "string",
      "enum": [
       "order",
       "sale_movement",
       "waste",
       "expense",
       "purchase_line"
      ]
     },
     "amount": {
      "type": "string",
      "description": "The entry's contribution to the metric (2 dp). Omitted on purchases / cogs / waste when the caller lacks costs.view (PAN-201)."
     },
     "at": {
      "type": "string",
      "format": "date-time"
     },
     "title": {
      "type": "string",
      "nullable": true,
      "description": "Ingredient name",
      "category name or table label.": null
     },
     "quantity": {
      "type": "string",
      "nullable": true
     },
     "unit": {
      "type": "string",
      "nullable": true
     },
     "unit_cost": {
      "type": "string",
      "nullable": true,
      "description": "Omitted when the caller lacks costs.view (PAN-201)."
     },
     "created_by_name": {
      "type": "string",
      "nullable": true,
      "description": "Who created the entry (snapshot). PAN-343: a blank waste name with created_by_user_id set is filled at read time as on ingredient movements."
     },
     "created_by_user_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true,
      "description": "PAN-224. Set on waste entries; null for other kinds / legacy."
     },
     "note": {
      "type": "string",
      "nullable": true
     },
     "waste_reason": {
      "type": "string",
      "nullable": true
     },
     "order_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true
     },
     "order_no": {
      "type": "integer",
      "nullable": true
     },
     "expense_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true
     },
     "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true
     },
     "amended": {
      "type": "boolean"
     },
     "can_amend": {
      "type": "boolean",
      "description": "Legacy PAN-156; for purchase_line mirrors can_edit."
     },
     "can_void": {
      "type": "boolean",
      "description": "PAN-335 purchase_line: stock.void, creator window, or stock.override. Not finance.amend or stock.correct."
     },
     "can_edit": {
      "type": "boolean",
      "description": "PAN-202 purchase_line: finance.amend or creator within window."
     },
     "can_correct": {
      "type": "boolean",
      "description": "PAN-225 purchase_line: stock.correct or stock.override. Correct edits in place; quantity must be > 0."
     },
     "eligibility": {
      "type": "string",
      "nullable": true,
      "description": "within_24h_or_stock_unused when the creator window applies."
     },
     "stock_unused": {
      "type": "boolean",
      "nullable": true,
      "description": "True when on-hand stock still covers this line qty."
     },
     "status": {
      "type": "string",
      "nullable": true,
      "enum": [
       "active",
       "voided"
      ],
      "description": "PAN-202 purchase_line status."
     },
     "voided": {
      "type": "boolean",
      "description": "True when this purchase line was voided."
     },
     "voided_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true
     },
     "voided_by_name": {
      "type": "string",
      "nullable": true,
      "description": "Who made the latest void or correction of this purchase line (PAN-322 / PAN-336): the actor's name: the shard staff login name, else the directory account display name, else its email; never the creator, never another business's staff or owner, never a payroll employee."
     },
     "void_reason": {
      "type": "string",
      "nullable": true
     },
     "replacement_line_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true,
      "description": "Forward link from a voided line to its correction replacement."
     },
     "replacement_expense_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true
     },
     "replaces_line_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true,
      "description": "Back-link on a legacy void+replace corrected line to the voided original (pre-PAN-222)."
     },
     "corrected": {
      "type": "boolean",
      "description": "PAN-222. True when this purchase line was corrected in place (single history row)."
     },
     "original_quantity": {
      "type": "string",
      "nullable": true,
      "description": "PAN-222. Quantity before the first in-place correct (from finance_amendments.before)."
     },
     "locked_reason": {
      "type": "string",
      "nullable": true,
      "enum": [
       "order",
       "permission",
       "stock",
       "payroll",
       "window",
       "voided",
       "insufficient_stock",
       null
      ],
      "description": "PAN-202 purchase_line: permission | window | voided | insufficient_stock."
     }
    }
   },
   "DayEntriesPage": {
    "type": "object",
    "properties": {
     "day": {
      "type": "string",
      "format": "date"
     },
     "metric": {
      "type": "string"
     },
     "total": {
      "type": "string",
      "description": "The metric's day total (2 dp). Omitted on purchases / cogs / waste when the caller lacks costs.view (PAN-201)."
     },
     "data": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/DayEntry"
      }
     },
     "next_cursor": {
      "type": "string",
      "nullable": true
     }
    }
   },
   "Notification": {
    "type": "object",
    "description": "PAN-147. One in-app notification for the caller. Types, severity, recipients, params and target - `stock_out` (urgent; owner, manager; params `ingredient_id`, `ingredient_name`; target `shopping_list` with the ingredient id), `stock_low` (warning; same as stock_out; when stock drops to its minimum), `order_unpaid` (warning; owner, manager, cashier; 15 minutes after the last line was served and the order is still unpaid, once per order; params `order_number`, `channel` = `dine_in` or `takeaway`; target `order`), `invite_accepted` (normal; owner; on the member's first sign-in; params `name`; target `staff` = the staff login id for employee-code staff or the membership id for Google invites), `payroll_ready` (normal; owner; when a draft payroll run is created; params `period` = {start, end} dates; target `payroll` = run id), `stock_count_saved` (normal; owner and managers other than the counter; params `actor_name`, `lines`; target `stock_count` = first audit id), `plan_renews` (severity by stage, see below; owner; Monthly businesses only; params `date` (YYYY-MM-DD in the business timezone) and `stage` = `renewal` (7 days before the renewal), `grace` (the plan lapsed; date = grace end), `paywall` (grace over; date = deletion day) or `deletion` (7 days before deletion); target `plan` = business id; each stage and date once). While an unread notification with the same type and target exists, a new one bumps its `created_at` (and params) instead of adding a row; for `plan_renews` that refresh also replaces `severity` and `params.stage` and `params.date` when the stage moved on.\n\nplan_renews severity by stage (PAN-148):\n\n| stage | severity |\n|---|---|\n| renewal | normal |\n| grace | warning |\n| paywall | urgent |\n| deletion | urgent |",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "type": {
      "type": "string",
      "enum": [
       "stock_out",
       "stock_low",
       "order_unpaid",
       "invite_accepted",
       "payroll_ready",
       "stock_count_saved",
       "plan_renews"
      ]
     },
     "severity": {
      "type": "string",
      "enum": [
       "urgent",
       "warning",
       "normal"
      ]
     },
     "params": {
      "type": "object",
      "additionalProperties": true,
      "example": {
       "ingredient_id": "7a1c9a52-3c1b-4d0e-9f7b-2b1d7f9e8c11",
       "ingredient_name": "Milk"
      }
     },
     "target": {
      "type": "object",
      "properties": {
       "kind": {
        "type": "string",
        "enum": [
         "shopping_list",
         "order",
         "staff",
         "payroll",
         "stock_count",
         "plan"
        ]
       },
       "id": {
        "type": "string"
       }
      },
      "required": [
       "kind",
       "id"
      ]
     },
     "read_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    },
    "required": [
     "id",
     "type",
     "severity",
     "params",
     "target",
     "read_at",
     "created_at"
    ]
   },
   "NotificationsRead": {
    "type": "object",
    "description": "Exactly one of `ids` (1-200) or `all: true`.",
    "properties": {
     "ids": {
      "type": "array",
      "maxItems": 200,
      "items": {
       "type": "string",
       "format": "uuid"
      }
     },
     "all": {
      "type": "boolean"
     }
    }
   },
   "AccountExport": {
    "type": "object",
    "description": "E1 export (DELETE-ACCOUNT.md §2.6). `bytes`, `file_name`, `ready_at` and `expires_at` are set once ready.",
    "required": [
     "export_id",
     "state",
     "created_at"
    ],
    "properties": {
     "export_id": {
      "type": "string",
      "format": "uuid"
     },
     "state": {
      "type": "string",
      "enum": [
       "queued",
       "running",
       "ready",
       "failed",
       "expired"
      ]
     },
     "bytes": {
      "type": "integer",
      "format": "int64",
      "nullable": true
     },
     "expires_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "When the zip is deleted (24 hours after it was built)."
     },
     "download_url": {
      "type": "string",
      "nullable": true,
      "description": "Presigned R2 GET, valid 15 minutes, minted on each GET while `ready`. Never in email."
     },
     "file_name": {
      "type": "string",
      "nullable": true,
      "example": "panly-export-20261111-1430-WIB.zip"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "ready_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true
     },
     "row_counts": {
      "type": "object",
      "additionalProperties": true,
      "description": "Per business code, rows per CSV file name (`sales.csv` … `shifts.csv`), or `{skipped: reason}`. Same numbers as README.txt."
     }
    }
   },
   "Error": {
    "type": "object",
    "properties": {
     "error": {
      "type": "object",
      "properties": {
       "code": {
        "type": "string",
        "example": "validation_failed",
        "description": "Machine-readable code. Includes `shard_not_mapped` or `no_shard_available` on HTTP 503 when directory routing is enabled and the business is missing from the merchant→shard map (no silent fallback to the default DB)."
       },
       "message": {
        "type": "string",
        "example": "Human readable message"
       },
       "details": {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "field": {
           "type": "string",
           "example": "quantity"
          },
          "issue": {
           "type": "string",
           "example": "must be > 0"
          }
         }
        }
       },
       "request_id": {
        "type": "string",
        "example": "req_01HX..."
       },
       "permission": {
        "type": "string",
        "example": "orders.create",
        "description": "PAN-88. On 403 permission_denied, the permission key the caller is missing."
       },
       "member_count": {
        "type": "integer",
        "description": "PAN-89. On 409 role_in_use, how many members hold the role (deactivated members count)."
       },
       "used": {
        "type": "integer",
        "description": "On 409 staff_limit_reached, active non-owner memberships currently counted toward the seat cap."
       },
       "limit": {
        "type": "integer",
        "description": "On 409 staff_limit_reached, included (3) + extra_employee_accounts for this business."
       },
       "existing": {
        "type": "object",
        "description": "PAN-128. On 409 category_exists, the category that already has the name.",
        "properties": {
         "id": {
          "type": "string",
          "format": "uuid"
         },
         "name": {
          "type": "string",
          "example": "Food"
         }
        },
        "required": [
         "id",
         "name"
        ]
       },
       "retry_after_seconds": {
        "type": "integer",
        "minimum": 1,
        "description": "Seconds until the client may retry. Set on 429 responses together with the Retry-After header."
       }
      },
      "required": [
       "code",
       "message"
      ]
     }
    },
    "required": [
     "error"
    ]
   },
   "GoogleAuthRequest": {
    "type": "object",
    "properties": {
     "business_code": {
      "type": "string",
      "example": "KOPISENJA",
      "description": "PAN-107. Required when this call creates the business. Case-insensitive input, stored upper case. 422 `validation_failed` on field `business_code` with issue `required`, `too_short`, `too_long`, `invalid_characters` or `reserved`; 409 `business_code_taken`. Check it first with `GET /v1/merchant-codes/{code}/availability`. Needed only when this sign-in creates the first business (new account, no invite_token). Ignored when the account already has a business or redeems an invite."
     },
     "currency": {
      "type": "string",
      "enum": [
       "IDR",
       "USD",
       "SGD",
       "MYR",
       "EUR"
      ],
      "example": "IDR",
      "description": "PAN-90. Optional, default IDR. Used only when this sign-in creates a new merchant. Unknown code is 422 `validation_failed` (field `currency`). Locked once the merchant exists."
     },
     "id_token": {
      "type": "string",
      "example": "eyJhbGciOi...",
      "description": "Google ID token obtained by the client (Google Sign-In / OAuth Playground)."
     },
     "merchant_name": {
      "type": "string",
      "example": "Warung Kopi Senja",
      "description": "Optional. Used only when this sign-in creates a new merchant."
     },
     "invite_token": {
      "type": "string",
      "example": "inv_...",
      "description": "Optional. Staff invitation link token. If valid (not used, not revoked, created less than 30 minutes ago) the signed-in account joins the inviting merchant with the invited role instead of creating a merchant. Not bound to an email: whoever opens the link and signs in first gets it."
     }
    },
    "required": [
     "id_token"
    ]
   },
   "RefreshRequest": {
    "type": "object",
    "properties": {
     "refresh_token": {
      "type": "string",
      "example": "rt_..."
     }
    },
    "required": [
     "refresh_token"
    ]
   },
   "Account": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "email": {
      "type": "string",
      "example": "owner@example.com"
     },
     "email_verified": {
      "type": "boolean"
     },
     "display_name": {
      "type": "string",
      "example": "Elmer",
      "nullable": true
     },
     "picture_url": {
      "type": "string",
      "example": "https://lh3.googleusercontent.com/...",
      "nullable": true
     },
     "last_login_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z",
      "nullable": true
     },
     "language": {
      "type": "string",
      "example": "id",
      "nullable": true,
      "description": "PAN-93. Preferred language code (`en`, `id`, `pt-BR`), null when the account follows the device. Set with `PATCH /v1/me`."
     }
    },
    "description": "The person (one per Google account, keyed by google_sub). Not tied to a merchant."
   },
   "MeUpdate": {
    "type": "object",
    "description": "PAN-93. Body of `PATCH /v1/me`.",
    "properties": {
     "language": {
      "type": "string",
      "nullable": true,
      "pattern": "^[a-z]{2,3}(-[A-Za-z]{2,4})?$",
      "example": "id",
      "description": "Language code, normalised on save (primary subtag lower case, 2-letter region upper case). `null` clears it."
     }
    },
    "required": [
     "language"
    ]
   },
   "Membership": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "merchant_id": {
      "type": "string",
      "pattern": "^[A-Z0-9]{3,16}$",
      "example": "CAFE42"
     },
     "role": {
      "type": "string",
      "enum": [
       "owner",
       "manager",
       "cashier",
       "kitchen",
       "custom"
      ],
      "description": "PAN-88. `custom` when the member has a custom role; see `role` and `permissions` on the response for the role id, name and keys."
     },
     "is_active": {
      "type": "boolean"
     }
    },
    "description": "The account's role in ONE merchant."
   },
   "Me": {
    "type": "object",
    "properties": {
     "account": {
      "$ref": "#/components/schemas/Account"
     },
     "membership": {
      "$ref": "#/components/schemas/Membership"
     },
     "merchant": {
      "$ref": "#/components/schemas/Merchant"
     },
     "role": {
      "$ref": "#/components/schemas/RoleInfo"
     },
     "permissions": {
      "$ref": "#/components/schemas/PermissionList"
     },
     "payment": {
      "$ref": "#/components/schemas/BillingStatus"
     },
     "is_staff": {
      "type": "boolean",
      "description": "PAN-112. True when the caller signed in as a staff login (employee ID and password). Owners and other Google accounts are false. Use this instead of guessing from the account email, which for a staff login is an internal placeholder, not a real address."
     },
     "employee_code": {
      "type": "string",
      "nullable": true,
      "example": "KOPISENJA-SARI",
      "description": "PAN-112. The employee ID of a staff login; null when `is_staff` is false."
     },
     "seats": {
      "$ref": "#/components/schemas/StaffSeats"
     }
    }
   },
   "RoleInfo": {
    "type": "object",
    "description": "PAN-88. The caller's role in this merchant.",
    "properties": {
     "id": {
      "type": "string",
      "description": "`owner`, `manager`, `cashier`, `kitchen` for the owner and the starter roles, the role uuid for a custom role.",
      "example": "cashier"
     },
     "name": {
      "type": "string",
      "description": "Display name (`Owner`, `Manager`, `Cashier`, `Fulfilment`, or the custom role name).",
      "example": "Cashier"
     },
     "kind": {
      "type": "string",
      "enum": [
       "owner",
       "starter",
       "custom"
      ]
     }
    },
    "required": [
     "id",
     "name",
     "kind"
    ]
   },
   "PermissionDef": {
    "type": "object",
    "description": "PAN-225. One entry of GET /v1/permissions.",
    "properties": {
     "key": {
      "$ref": "#/components/schemas/PermissionKey"
     },
     "group": {
      "type": "string",
      "enum": [
       "orders",
       "stock",
       "costs",
       "reports",
       "payroll",
       "staff"
      ],
      "description": "Grouping id (formerly area); the app owns the display text."
     },
     "label_key": {
      "type": "string",
      "description": "i18n key, `perm.<permission key>` (e.g. `perm.stock.correct`).",
      "example": "perm.stock.correct"
     },
     "requires": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PermissionKey"
      },
      "description": "Closure of the key's direct Requires (catalog order)."
     }
    },
    "required": [
     "key",
     "group",
     "label_key",
     "requires"
    ]
   },
   "Role": {
    "type": "object",
    "description": "PAN-89. A role of this merchant.",
    "properties": {
     "id": {
      "type": "string",
      "description": "`owner`, `manager`, `cashier`, `kitchen` or the custom role uuid."
     },
     "name": {
      "type": "string",
      "example": "Floor lead"
     },
     "kind": {
      "type": "string",
      "enum": [
       "owner",
       "starter",
       "custom"
      ]
     },
     "permissions": {
      "$ref": "#/components/schemas/PermissionList"
     },
     "member_count": {
      "type": "integer",
      "description": "Members holding the role, deactivated ones included (they keep their role and block deleting it)."
     }
    },
    "required": [
     "id",
     "name",
     "kind",
     "permissions",
     "member_count"
    ]
   },
   "RoleCreate": {
    "type": "object",
    "properties": {
     "name": {
      "type": "string",
      "maxLength": 40,
      "description": "Trimmed, 1-40 characters, unique per merchant ignoring case. Owner, Manager, Cashier, Kitchen and Fulfilment are reserved (409 `role_name_taken`)."
     },
     "permissions": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PermissionKey"
      },
      "description": "Required unless `copy_from` is set. An empty list is allowed."
     },
     "copy_from": {
      "type": "string",
      "description": "A starter id or custom role uuid; its permissions are used when `permissions` is omitted (the owner's tickable keys for `owner`)."
     }
    },
    "required": [
     "name"
    ]
   },
   "RolePatch": {
    "type": "object",
    "description": "At least one field. `permissions` replaces the whole list.",
    "properties": {
     "name": {
      "type": "string",
      "maxLength": 40
     },
     "permissions": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PermissionKey"
      }
     }
    }
   },
   "PermissionKey": {
    "type": "string",
    "enum": [
     "orders.view",
     "orders.create",
     "orders.prepare",
     "orders.serve",
     "orders.complete",
     "orders.cancel",
     "orders.queue",
     "items.view",
     "items.manage",
     "stock.view",
     "stock.manage",
     "shopping.manage",
     "stock.void",
     "stock.correct",
     "stock.override",
     "costs.view",
     "expenses.view",
     "expenses.manage",
     "finance.amend",
     "reports.sales",
     "reports.cashflow",
     "payroll.shifts",
     "payroll.manage",
     "staff.manage",
     "roles.manage",
     "settings.manage"
    ]
   },
   "PermissionList": {
    "type": "array",
    "description": "PAN-88. Every permission the caller holds right now, in catalog order. The owner has all 26.",
    "items": {
     "$ref": "#/components/schemas/PermissionKey"
    }
   },
   "Member": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "account_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "email": {
      "type": "string",
      "example": "barista@example.com"
     },
     "display_name": {
      "type": "string",
      "example": "Sari",
      "nullable": true
     },
     "picture_url": {
      "type": "string",
      "example": "https://lh3.googleusercontent.com/...",
      "nullable": true
     },
     "role": {
      "type": "string",
      "enum": [
       "owner",
       "manager",
       "cashier",
       "kitchen",
       "custom"
      ],
      "description": "`custom` when the member has a custom role (see `role_id`)."
     },
     "role_id": {
      "type": "string",
      "description": "PAN-89. `owner`, `manager`, `cashier`, `kitchen`, or the uuid of the custom role. Same ids as `GET /v1/roles`.",
      "example": "cashier"
     },
     "role_name": {
      "type": "string",
      "description": "PAN-89. Owner, Manager, Cashier, Fulfilment or the custom role name.",
      "example": "Cashier"
     },
     "is_active": {
      "type": "boolean"
     },
     "joined_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     }
    },
    "description": "A membership of the caller's merchant joined with its account. `id` is the membership id."
   },
   "MemberUpdate": {
    "type": "object",
    "description": "At least one of `role_id`, `role`, `is_active`. `role_id` and `role` cannot be combined.",
    "properties": {
     "role_id": {
      "type": "string",
      "description": "PAN-89. `manager`, `cashier`, `kitchen` (Fulfilment), `owner`, or the uuid of a custom role of this merchant. Moving a person to another role ignores the 3-account cap. The owner cannot be moved (409 `role_readonly`). Unknown ids are 422.",
      "example": "cashier"
     },
     "role": {
      "type": "string",
      "description": "Older way to set a starter role; `custom` is not accepted here, use `role_id`.",
      "enum": [
       "owner",
       "manager",
       "cashier",
       "kitchen"
      ]
     },
     "is_active": {
      "type": "boolean"
     }
    }
   },
   "CodeAvailability": {
    "type": "object",
    "properties": {
     "available": {
      "type": "boolean"
     },
     "reason": {
      "type": "string",
      "nullable": true,
      "enum": [
       "taken",
       "reserved",
       "too_short",
       "too_long",
       "invalid_characters"
      ],
      "description": "Null when `available` is true."
     }
    },
    "required": [
     "available",
     "reason"
    ]
   },
   "MyMerchant": {
    "type": "object",
    "properties": {
     "business_code": {
      "type": "string",
      "example": "KOPISENJA",
      "description": "PAN-107. The business code, always upper case. 3-16 characters A-Z and 0-9, unique across all businesses (case-insensitive), and never changes after creation."
     },
     "currency": {
      "$ref": "#/components/schemas/Currency"
     },
     "merchant_id": {
      "type": "string",
      "pattern": "^[A-Z0-9]{3,16}$",
      "example": "CAFE42"
     },
     "merchant_name": {
      "type": "string",
      "example": "Warung Kopi Senja"
     },
     "tier": {
      "type": "string",
      "enum": [
       "FREE",
       "MONTHLY",
       "LIFETIME"
      ]
     },
     "role": {
      "type": "string",
      "enum": [
       "owner",
       "manager",
       "cashier",
       "kitchen",
       "custom"
      ]
     },
     "role_info": {
      "$ref": "#/components/schemas/RoleInfo"
     },
     "membership_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "subscription_status": {
      "type": "string",
      "enum": [
       "none",
       "active",
       "past_due",
       "unpaid",
       "canceled"
      ]
     },
     "current": {
      "type": "boolean",
      "description": "True for the merchant the presented JWT is scoped to."
     },
     "over_limit": {
      "type": "boolean",
      "description": "PAN-117. True while this business was not kept when its owner reduced extra businesses (grace, then paused, deleted at day 60). Show the \"Over limit\" tag."
     },
     "add_on_ends_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "PAN-117. When the earliest pending add-on reduction of this business takes effect. Null when none (show the \"Extra (ends in N days)\" tag only when set)."
     },
     "add_on_ends_in_days": {
      "type": "integer",
      "nullable": true,
      "description": "PAN-117. Days until `add_on_ends_at`, rounded up."
     },
     "covered_by": {
      "nullable": true,
      "allOf": [
       {
        "$ref": "#/components/schemas/CoveredBy"
       }
      ],
      "description": "PAN-396. The owner's business whose Premium covers this one (`tier` and `subscription_status` are then that plan). Null when the plan is this business's own. Show the row as Premium."
     },
     "over_business_limit": {
      "type": "boolean",
      "description": "PAN-396. True when the owner has Premium but this business is beyond the owner's business limit (402 until the owner buys `extra_businesses`)."
     }
    }
   },
   "MerchantCreate": {
    "type": "object",
    "required": [
     "business_code",
     "merchant_name"
    ],
    "properties": {
     "business_code": {
      "type": "string",
      "example": "KOPISENJA2",
      "description": "PAN-107. Required when this call creates the business. Case-insensitive input, stored upper case. 422 `validation_failed` on field `business_code` with issue `required`, `too_short`, `too_long`, `invalid_characters` or `reserved`; 409 `business_code_taken`. Check it first with `GET /v1/merchant-codes/{code}/availability`."
     },
     "currency": {
      "type": "string",
      "enum": [
       "IDR",
       "USD",
       "SGD",
       "MYR",
       "EUR"
      ],
      "example": "IDR",
      "description": "PAN-90. Optional, default IDR. Unknown code is 422 `validation_failed` (field `currency`). It cannot be changed later."
     },
     "merchant_name": {
      "type": "string",
      "example": "Warung Kopi Senja 2"
     },
     "timezone": {
      "type": "string",
      "example": "Asia/Jakarta",
      "description": "Optional IANA timezone, default Asia/Jakarta."
     }
    }
   },
   "SwitchMerchantRequest": {
    "type": "object",
    "properties": {
     "merchant_id": {
      "type": "string",
      "pattern": "^[A-Z0-9]{3,16}$",
      "example": "CAFE42",
      "description": "PAN-121 - target business code (case-insensitive, stored upper case). Optional when business_code is sent; at least one of the two is required. An old uuid is 422 invalid_characters."
     },
     "business_code": {
      "type": "string",
      "pattern": "^[A-Za-z0-9]{3,16}$",
      "example": "CAFE42",
      "description": "PAN-121: alias of merchant_id (the business code). Must be the same code as merchant_id when both are sent."
     },
     "refresh_token": {
      "type": "string",
      "example": "rt_...",
      "description": "The account's current refresh token; rotated and re-scoped to the new merchant."
     }
    },
    "required": [
     "refresh_token"
    ]
   },
   "DeletionInfo": {
    "type": "object",
    "description": "D3. The pending account deletion on a restricted session or a 403 `ACCOUNT_DELETION_PENDING`.",
    "properties": {
     "job_id": {
      "type": "string",
      "format": "uuid"
     },
     "state": {
      "type": "string",
      "enum": [
       "scheduled",
       "running"
      ]
     },
     "execute_after": {
      "type": "string",
      "format": "date-time"
     }
    },
    "required": [
     "job_id",
     "state",
     "execute_after"
    ]
   },
   "AccountDeletionJob": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "state": {
      "type": "string",
      "enum": [
       "scheduled",
       "running",
       "failed"
      ]
     },
     "execute_after": {
      "type": "string",
      "format": "date-time"
     },
     "businesses": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "code": {
         "type": "string"
        },
        "state": {
         "type": "string",
         "example": "queued"
        }
       },
       "required": [
        "code",
        "state"
       ]
      }
     }
    },
    "required": [
     "id",
     "state",
     "execute_after",
     "businesses"
    ]
   },
   "AccountDeletionPreview": {
    "type": "object",
    "properties": {
     "email": {
      "type": "string"
     },
     "phrase": {
      "type": "string",
      "example": "I agree to delete this account permanently"
     },
     "grace_days": {
      "type": "integer",
      "example": 7
     },
     "businesses": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "code": {
         "type": "string"
        },
        "name": {
         "type": "string"
        },
        "staff_count": {
         "type": "integer"
        },
        "subscription": {
         "type": "object",
         "properties": {
          "status": {
           "type": "string",
           "nullable": true
          },
          "renews_at": {
           "type": "string",
           "format": "date-time",
           "nullable": true
          }
         }
        }
       },
       "required": [
        "code",
        "name",
        "staff_count",
        "subscription"
       ]
      }
     },
     "other_memberships": {
      "type": "integer"
     },
     "refund": {
      "type": "string",
      "enum": [
       "none"
      ]
     },
     "books_warning": {
      "type": "string",
      "example": "Download your data first. Deleting removes all sales, expenses and stock records."
     },
     "export": {
      "type": "object",
      "properties": {
       "path": {
        "type": "string",
        "example": "/v1/account/export"
       },
       "latest": {
        "nullable": true,
        "allOf": [
         {
          "$ref": "#/components/schemas/AccountExport"
         }
        ]
       }
      }
     },
     "job": {
      "nullable": true,
      "allOf": [
       {
        "$ref": "#/components/schemas/AccountDeletionJob"
       }
      ]
     }
    },
    "required": [
     "email",
     "phrase",
     "grace_days",
     "businesses",
     "other_memberships",
     "refund",
     "books_warning",
     "export",
     "job"
    ]
   },
   "AccountDeletionConfirm": {
    "type": "object",
    "properties": {
     "confirm_email": {
      "type": "string",
      "maxLength": 320
     },
     "confirm_business_names": {
      "type": "array",
      "maxItems": 100,
      "items": {
       "type": "string",
       "maxLength": 320
      }
     },
     "confirm_phrase": {
      "type": "string",
      "maxLength": 320
     },
     "google_id_token": {
      "type": "string",
      "nullable": true
     }
    },
    "required": [
     "confirm_email",
     "confirm_business_names",
     "confirm_phrase"
    ]
   },
   "AccountDeletionScheduled": {
    "type": "object",
    "properties": {
     "job_id": {
      "type": "string",
      "format": "uuid"
     },
     "state": {
      "type": "string",
      "enum": [
       "scheduled"
      ]
     },
     "execute_after": {
      "type": "string",
      "format": "date-time"
     }
    },
    "required": [
     "job_id",
     "state",
     "execute_after"
    ]
   },
   "AccountDeletionCancelled": {
    "description": "`TokenResponse` (full session) plus `state`, or only `{state:\"cancelled\"}`.",
    "allOf": [
     {
      "$ref": "#/components/schemas/TokenResponse"
     },
     {
      "type": "object",
      "properties": {
       "state": {
        "type": "string",
        "enum": [
         "cancelled"
        ]
       }
      },
      "required": [
       "state"
      ]
     }
    ]
   },
   "TokenResponse": {
    "type": "object",
    "properties": {
     "access_token": {
      "type": "string",
      "example": "eyJ...",
      "description": "Short-lived access JWT (~15 min), scoped to one merchant."
     },
     "refresh_token": {
      "type": "string",
      "example": "rt_...",
      "description": "Opaque, rotating, single use, belongs to the ACCOUNT (not a merchant); keeps working across merchant switches. Only its SHA-256 is stored."
     },
     "token_type": {
      "type": "string",
      "example": "Bearer"
     },
     "expires_in": {
      "type": "integer",
      "example": 900
     },
     "is_new_merchant": {
      "type": "boolean"
     },
     "account": {
      "$ref": "#/components/schemas/Account"
     },
     "membership": {
      "$ref": "#/components/schemas/Membership"
     },
     "merchant": {
      "$ref": "#/components/schemas/Merchant"
     },
     "role": {
      "$ref": "#/components/schemas/RoleInfo"
     },
     "permissions": {
      "$ref": "#/components/schemas/PermissionList"
     },
     "session_scope": {
      "type": "string",
      "enum": [
       "full",
       "account_deletion"
      ],
      "description": "D3. `full` for every normal session. `account_deletion` when the account has a scheduled deletion\n(DELETE-ACCOUNT.md §2.3): Google sign-in during the 7-day grace period returns this restricted session\ninstead of opening a business. It is bound to no business (`membership`, `merchant` and `role` are null,\n`permissions` is empty), the access token carries claim `scope: account_deletion` and no merchant claims,\nand refresh keeps the scope; the refresh token never outlives `execute_after`. It reaches only\n`/v1/account/deletion`, `/v1/account/export*` and logout; every other route is 403\n`ACCOUNT_DELETION_PENDING` with `details.deletion`. Sign-in when the job is running or due is 409\n`DELETION_ALREADY_RUNNING`.\n"
     },
     "deletion": {
      "nullable": true,
      "allOf": [
       {
        "$ref": "#/components/schemas/DeletionInfo"
       }
      ],
      "description": "D3. Set only on an `account_deletion` session."
     }
    },
    "required": [
     "access_token",
     "refresh_token",
     "token_type",
     "expires_in"
    ]
   },
   "Currency": {
    "type": "object",
    "description": "PAN-90. The business currency, chosen at setup and locked once the merchant has orders. Allowlist (code, symbol,\n`minor_units`): IDR Rp 0, USD $ 2, SGD S$ 2, MYR RM 2, EUR € 2. Amounts in every payload stay decimal strings with\n2 decimal places. Amount input (PAN-92) does not depend on the currency or on `minor_units`: every currency,\nIDR included, accepts up to 2 decimals (`12000.50` is fine for IDR); 3 or more decimals are 422\n`validation_failed`. `minor_units` is for display only. Stored data is not changed.\n",
    "properties": {
     "code": {
      "type": "string",
      "enum": [
       "IDR",
       "USD",
       "SGD",
       "MYR",
       "EUR"
      ],
      "example": "IDR"
     },
     "symbol": {
      "type": "string",
      "example": "Rp"
     },
     "minor_units": {
      "type": "integer",
      "enum": [
       0,
       2
      ],
      "example": 0
     }
    },
    "required": [
     "code",
     "symbol",
     "minor_units"
    ]
   },
   "Merchant": {
    "type": "object",
    "properties": {
     "currency": {
      "$ref": "#/components/schemas/Currency"
     },
     "id": {
      "type": "string",
      "pattern": "^[A-Z0-9]{3,16}$",
      "example": "CAFE42"
     },
     "business_code": {
      "type": "string",
      "example": "KOPISENJA",
      "description": "PAN-107. The business code, always upper case. 3-16 characters A-Z and 0-9, unique across all businesses (case-insensitive), and never changes after creation."
     },
     "merchant_name": {
      "type": "string",
      "example": "Warung Kopi Senja"
     },
     "tier": {
      "type": "string",
      "enum": [
       "FREE",
       "MONTHLY",
       "LIFETIME"
      ]
     },
     "timezone": {
      "type": "string",
      "example": "Asia/Jakarta"
     },
     "storage": {
      "type": "object",
      "properties": {
       "used_bytes": {
        "type": "integer",
        "format": "int64",
        "example": 5243880
       },
       "cap_bytes": {
        "type": "integer",
        "format": "int64",
        "example": 104857600,
        "description": "FREE 104857600 (100 MiB); MONTHLY and LIFETIME 5368709120 (5 GiB). Binary units."
       }
      }
     },
     "subscription": {
      "type": "object",
      "properties": {
       "status": {
        "type": "string",
        "enum": [
         "none",
         "active",
         "past_due",
         "unpaid",
         "canceled"
        ]
       },
       "current_period_end": {
        "type": "string",
        "format": "date-time",
        "example": "2026-10-04T08:30:00Z",
        "nullable": true
       },
       "payment_failed_at": {
        "type": "string",
        "format": "date-time",
        "example": "2026-10-04T08:30:00Z",
        "nullable": true
       },
       "wipe_deadline": {
        "type": "string",
        "format": "date-time",
        "description": "Day 60 of the lapse (PAN-116), meaning the period end, or payment_failed_at for a failed charge, plus 60 days. Present only for a MONTHLY merchant whose plan has lapsed. Data may be deleted after this date by a purge job that is OFF unless LAPSE_PURGE_ENABLED=true.",
        "nullable": true
       },
       "wipe_warning_stage": {
        "type": "integer",
        "minimum": 0,
        "maximum": 3
       }
      }
     },
     "created_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     },
     "plan_state": {
      "type": "string",
      "enum": [
       "free",
       "plan_selected_pending_payment",
       "active_monthly",
       "active_lifetime",
       "payment_failed"
      ],
      "description": "Derived. `plan_selected_pending_payment` means a choice is saved and nobody was charged; the effective plan is still Free."
     },
     "covered_by": {
      "nullable": true,
      "allOf": [
       {
        "$ref": "#/components/schemas/CoveredBy"
       }
      ],
      "description": "PAN-396. The owner's business whose Premium covers this one: `tier`, `subscription`, `plan_state`, `limits` and the storage cap are then that plan. Null when the plan is this business's own."
     },
     "plan_selection": {
      "$ref": "#/components/schemas/PlanSelection"
     },
     "limits": {
      "$ref": "#/components/schemas/MerchantLimits"
     },
     "add_ons": {
      "type": "array",
      "description": "PAN-117. Add-ons bought for THIS business that are in force now, `[{key, quantity}]` (empty when none). They are already in `limits.effective`.",
      "items": {
       "type": "object",
       "properties": {
        "key": {
         "type": "string"
        },
        "quantity": {
         "type": "integer"
        }
       }
      }
     }
    }
   },
   "MerchantUpdate": {
    "type": "object",
    "description": "PAN-90. Sending `currency` (any value) is 422 `currency_locked`; the currency is set when the business is created. PAN-107. Sending `business_code` (any value, even the current one) is 422 `business_code_locked`; the code never changes.",
    "properties": {
     "merchant_name": {
      "type": "string",
      "example": "Warung Kopi Senja"
     },
     "timezone": {
      "type": "string",
      "example": "Asia/Jakarta",
      "description": "IANA timezone name; days in reports are bucketed in it."
     }
    }
   },
   "InvitationCreate": {
    "type": "object",
    "description": "Send `role_id` or `role`, not both.",
    "properties": {
     "role_id": {
      "type": "string",
      "description": "PAN-89. `manager`, `cashier`, `kitchen`, or the uuid of a custom role of this merchant. `owner` is never invitable."
     },
     "role": {
      "type": "string",
      "description": "Older way to pick a starter role.",
      "enum": [
       "manager",
       "cashier",
       "kitchen"
      ]
     }
    }
   },
   "StaffCreate": {
    "type": "object",
    "required": [
     "name",
     "username"
    ],
    "properties": {
     "name": {
      "type": "string",
      "example": "Sari Wulandari",
      "description": "Display name; it is what orders and audit rows keep."
     },
     "username": {
      "type": "string",
      "example": "sari",
      "description": "The part of the employee ID the owner chooses, 3-20 characters (letters, digits, `.`, `_`), case-insensitive. The full ID is `{business_code}-{USERNAME}`."
     },
     "role_id": {
      "type": "string",
      "example": "cashier",
      "description": "manager, cashier, kitchen or a custom role uuid. Not `owner`."
     },
     "role": {
      "type": "string",
      "enum": [
       "manager",
       "cashier",
       "kitchen"
      ],
      "description": "The older way to send a starter role. Not together with `role_id`."
     },
     "email": {
      "type": "string",
      "format": "email",
      "example": "sari@example.com",
      "description": "Optional contact address for setup and reset links (PAN-111). Lower-cased; a bare address only."
     }
    }
   },
   "StaffUpdate": {
    "type": "object",
    "properties": {
     "name": {
      "type": "string",
      "example": "Sari W."
     },
     "role_id": {
      "type": "string",
      "example": "kitchen"
     },
     "role": {
      "type": "string",
      "enum": [
       "manager",
       "cashier",
       "kitchen"
      ]
     },
     "is_active": {
      "type": "boolean"
     },
     "email": {
      "type": "string",
      "nullable": true,
      "format": "email",
      "description": "Set or change the contact address; null or an empty string removes it (PAN-111)."
     }
    }
   },
   "StaffCreated": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "employee_code": {
      "type": "string",
      "example": "KOPISENJA-SARI"
     },
     "name": {
      "type": "string",
      "example": "Sari Wulandari"
     },
     "role": {
      "type": "string",
      "enum": [
       "manager",
       "cashier",
       "kitchen",
       "custom"
      ],
      "description": "`custom` when the login has a custom role (see `role_id`)."
     },
     "role_id": {
      "type": "string",
      "example": "cashier"
     },
     "role_name": {
      "type": "string",
      "example": "Cashier"
     },
     "setup_link": {
      "type": "string",
      "example": "https://app.panly.example/staff-setup?token=stp_...",
      "description": "One-time link, shown only in this response. The `token` query parameter goes to `POST /v1/auth/employee/setup`."
     },
     "expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the link stops working (7 days after it was made)."
     },
     "email": {
      "type": "string",
      "nullable": true,
      "description": "The contact address on the login, or null."
     },
     "email_queued": {
      "type": "boolean",
      "description": "True when the setup link was handed to the mail provider (email set and mail on). It does not mean delivered."
     }
    },
    "required": [
     "id",
     "employee_code",
     "name",
     "role",
     "setup_link",
     "expires_at",
     "email_queued"
    ]
   },
   "Staff": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "employee_code": {
      "type": "string",
      "example": "KOPISENJA-SARI"
     },
     "name": {
      "type": "string",
      "example": "Sari Wulandari"
     },
     "role": {
      "type": "string",
      "enum": [
       "manager",
       "cashier",
       "kitchen",
       "custom"
      ]
     },
     "role_id": {
      "type": "string",
      "example": "cashier"
     },
     "role_name": {
      "type": "string",
      "example": "Cashier"
     },
     "is_active": {
      "type": "boolean"
     },
     "setup_status": {
      "type": "string",
      "enum": [
       "pending",
       "complete"
      ],
      "description": "`pending` until the person has chosen a password."
     },
     "setup_expires_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "When the newest unused setup link stops working; null once setup is complete."
     },
     "last_login_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "email": {
      "type": "string",
      "nullable": true,
      "description": "Contact address for setup and reset links (PAN-111), or null. Not a sign-in name."
     }
    }
   },
   "EmployeeForgotPasswordRequest": {
    "type": "object",
    "required": [
     "employee_code"
    ],
    "properties": {
     "employee_code": {
      "type": "string",
      "example": "KOPISENJA-SARI"
     }
    }
   },
   "ForgotPasswordAccepted": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "enum": [
       "accepted"
      ]
     },
     "message": {
      "type": "string",
      "example": "If this employee ID has an email address on file, a reset link has been sent to it."
     }
    }
   },
   "EmployeeLoginRequest": {
    "type": "object",
    "required": [
     "employee_code",
     "password"
    ],
    "properties": {
     "employee_code": {
      "type": "string",
      "example": "KOPISENJA-SARI",
      "description": "The full employee ID, any case."
     },
     "password": {
      "type": "string"
     }
    }
   },
   "EmployeeSetupPreviewRequest": {
    "type": "object",
    "required": [
     "token"
    ],
    "properties": {
     "token": {
      "type": "string",
      "example": "stp_..."
     }
    }
   },
   "EmployeeSetupRequest": {
    "type": "object",
    "required": [
     "token",
     "password"
    ],
    "properties": {
     "token": {
      "type": "string",
      "example": "stp_..."
     },
     "password": {
      "type": "string",
      "minLength": 8,
      "maxLength": 128,
      "description": "Password rules: 8-128 characters and not equal to the employee ID (case-insensitive). Refused with 422 `validation_failed`, field `password`, issue `required`, `too_short`, `too_long` or `same_as_employee_code` (there is no `weak_password` code). The link stays usable."
     }
    }
   },
   "EmployeeSetupInfo": {
    "type": "object",
    "description": "What a setup or reset link says about the person it is for (PAN-112 adds the business and role so the app can greet them before sign-in).",
    "properties": {
     "employee_code": {
      "type": "string",
      "example": "KOPISENJA-SARI"
     },
     "name": {
      "type": "string",
      "example": "Sari Wulandari"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "business_name": {
      "type": "string",
      "example": "Kopi Senja"
     },
     "business_code": {
      "type": "string",
      "example": "KOPISENJA"
     },
     "role": {
      "type": "string",
      "enum": [
       "manager",
       "cashier",
       "kitchen",
       "custom"
      ]
     },
     "role_id": {
      "type": "string",
      "example": "cashier",
      "description": "Starter role id, or the role uuid for a custom role."
     },
     "role_name": {
      "type": "string",
      "example": "Cashier"
     }
    }
   },
   "PublicConfig": {
    "type": "object",
    "required": [
     "payment",
     "premium_required"
    ],
    "properties": {
     "payment": {
      "type": "object",
      "properties": {
       "provider": {
        "type": "string",
        "enum": [
         "stub",
         "midtrans",
         "xendit"
        ],
        "description": "`stub` while payments are a test double; the others are reserved for real integrations."
       }
      }
     },
     "premium_required": {
      "type": "boolean"
     }
    }
   },
   "BillingStatus": {
    "type": "object",
    "description": "PAN-114. Where the business stands with Premium.",
    "properties": {
     "provider": {
      "type": "string",
      "example": "stub"
     },
     "premium_required": {
      "type": "boolean"
     },
     "paid": {
      "type": "boolean",
      "description": "Actively paid (Monthly inside its period, or Lifetime). False during grace and paywall."
     },
     "payment_required": {
      "type": "boolean",
      "description": "True when the Premium gate is closed right now (`premium_required` and phase `paywall` or `unpaid`). False during the grace days."
     },
     "plan_state": {
      "type": "string",
      "example": "active_monthly"
     },
     "tier": {
      "type": "string",
      "enum": [
       "FREE",
       "MONTHLY",
       "LIFETIME"
      ]
     },
     "subscription_status": {
      "type": "string",
      "example": "active"
     },
     "current_period_end": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "When the paid Monthly period ends; null for Lifetime and unpaid."
     },
     "phase": {
      "type": "string",
      "enum": [
       "active",
       "grace",
       "paywall",
       "unpaid"
      ],
      "description": "PAN-116. `active` paid or Lifetime; `grace` lapsed days 0-3 (full access); `paywall` lapsed day 4 on (402); `unpaid` never paid (402, never deleted)."
     },
     "lapsed_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "Day 0 of the lapse (period end, or the first failed charge). Null unless `phase` is grace or paywall."
     },
     "days_since_lapse": {
      "type": "integer",
      "nullable": true,
      "description": "Whole days since `lapsed_at` (0 on day 0). Null unless lapsed."
     },
     "grace_ends_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "`lapsed_at` + 4 days. Null unless lapsed."
     },
     "grace_days_remaining": {
      "type": "integer",
      "nullable": true,
      "description": "Days of full access left, rounded up: 4 on day 0, 1 on day 3. Null outside `grace`."
     },
     "deletion_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "`lapsed_at` + 60 days, when the purge job (off by default) may delete the business. OWNER only; null for staff and when not lapsed."
     },
     "days_until_deletion": {
      "type": "integer",
      "nullable": true,
      "description": "Days left until `deletion_at`, rounded up, 0 once it has passed. OWNER only; null for staff and when not lapsed."
     },
     "lapse_reason": {
      "type": "string",
      "nullable": true,
      "enum": [
       "payment",
       "add_on_reduced"
      ],
      "description": "PAN-117. Why the lapse fields are set. `payment`: the plan ran out. `add_on_reduced`: this business was not kept when its owner reduced extra businesses (the plan itself is paid, `paid` stays true, `plan_state` stays `active_monthly`); the owner fixes it with the add-on routes, not the pay screen. Null when not lapsed."
     },
     "covered_by": {
      "nullable": true,
      "allOf": [
       {
        "$ref": "#/components/schemas/CoveredBy"
       }
      ],
      "description": "PAN-396. The owner's business whose Premium covers this one; every plan field above is then that plan. Null when the plan is this business's own. On a covered business the pay screen is never shown while `paid` is true."
     },
     "over_business_limit": {
      "type": "boolean",
      "description": "PAN-396. True when the owner has Premium but this business is beyond the owner's business limit. Send the owner to Add-ons (`extra_businesses`), not to checkout."
     },
     "seats": {
      "$ref": "#/components/schemas/StaffSeats"
     }
    }
   },
   "CoveredBy": {
    "type": "object",
    "description": "PAN-396. The owner's business whose Premium plan covers this business.",
    "required": [
     "merchant_id",
     "merchant_name",
     "business_code"
    ],
    "properties": {
     "merchant_id": {
      "type": "string",
      "example": "QAK1"
     },
     "merchant_name": {
      "type": "string",
      "example": "QA Cafe"
     },
     "business_code": {
      "type": "string",
      "example": "QAK1"
     }
    }
   },
   "StaffSeats": {
    "type": "object",
    "description": "Staff/employee seat line for this business. included (always 3) + extra_employee_accounts = limit; used is active non-owner memberships (same predicate as EMP01 / add-ons employees.in_use).",
    "properties": {
     "included": {
      "type": "integer",
      "example": 3
     },
     "extra": {
      "type": "integer",
      "example": 0,
      "description": "Bought extra_employee_accounts for this business."
     },
     "limit": {
      "type": "integer",
      "example": 3,
      "description": "included + extra."
     },
     "used": {
      "type": "integer",
      "example": 2,
      "description": "Active non-owner memberships."
     }
    },
    "required": [
     "included",
     "extra",
     "limit",
     "used"
    ]
   },
   "AddOnLine": {
    "type": "object",
    "description": "PAN-117. One counted limit of one business.",
    "properties": {
     "included": {
      "type": "integer",
      "description": "What the plan includes (businesses 2, employees 3 on Premium)."
     },
     "extra": {
      "type": "integer",
      "description": "Extra bought for THIS business (in force now)."
     },
     "limit": {
      "type": "integer",
      "description": "`included` + `extra`."
     },
     "in_use": {
      "type": "integer",
      "description": "Businesses: how many the owner owns. Employees: active employee accounts of this business."
     },
     "account_limit": {
      "type": "integer",
      "description": "Businesses line only. How many businesses the owner may own right now: the highest `limit` among their businesses (never a sum). It can be above this business's own `limit`; use it for \"x of y businesses\"."
     },
     "pending": {
      "type": "object",
      "nullable": true,
      "description": "A reduction waiting for the end of the paid period.",
      "properties": {
       "extra": {
        "type": "integer",
        "description": "The extra quantity once it takes effect."
       },
       "effective_at": {
        "type": "string",
        "format": "date-time"
       },
       "ends_in_days": {
        "type": "integer",
        "description": "Days until `effective_at`, rounded up."
       }
      }
     }
    }
   },
   "AddOnBusiness": {
    "type": "object",
    "description": "PAN-117. One business the caller owns, with its add-on counts.",
    "properties": {
     "merchant_id": {
      "type": "string",
      "pattern": "^[A-Z0-9]{3,16}$"
     },
     "merchant_name": {
      "type": "string"
     },
     "business_code": {
      "type": "string"
     },
     "tier": {
      "type": "string",
      "enum": [
       "FREE",
       "MONTHLY",
       "LIFETIME"
      ]
     },
     "current": {
      "type": "boolean",
      "description": "True for the business the token is scoped to."
     },
     "eligible": {
      "type": "boolean",
      "description": "Whether add-ons can be changed for this business (active Premium plan)."
     },
     "ineligible_reason": {
      "type": "string",
      "nullable": true,
      "enum": [
       "not_premium",
       "lifetime",
       "payment_lapsed",
       "over_limit"
      ]
     },
     "current_period_end": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "When a reduction for this business takes effect."
     },
     "over_limit": {
      "type": "boolean",
      "description": "True while this business was not kept when extra businesses was reduced."
     },
     "covered_by": {
      "nullable": true,
      "allOf": [
       {
        "$ref": "#/components/schemas/CoveredBy"
       }
      ],
      "description": "PAN-396. The owner's business whose Premium covers this one (`tier` and `current_period_end` are then that plan). Null when the plan is this business's own."
     },
     "lapse": {
      "type": "object",
      "nullable": true,
      "description": "Set while `over_limit`. Same phases as the payment lapse.",
      "properties": {
       "reason": {
        "type": "string",
        "enum": [
         "add_on_reduced"
        ]
       },
       "phase": {
        "type": "string",
        "enum": [
         "grace",
         "paywall"
        ]
       },
       "lapsed_at": {
        "type": "string",
        "format": "date-time"
       },
       "grace_ends_at": {
        "type": "string",
        "format": "date-time"
       },
       "deletion_at": {
        "type": "string",
        "format": "date-time"
       },
       "days_left": {
        "type": "integer",
        "description": "Days until `deletion_at`, rounded up."
       }
      }
     },
     "businesses": {
      "$ref": "#/components/schemas/AddOnLine"
     },
     "employees": {
      "$ref": "#/components/schemas/AddOnLine"
     }
    }
   },
   "AddOnCost": {
    "type": "object",
    "description": "PAN-117. Add-on cost per month, amounts as decimal strings. Example numbers (catalog placeholder prices); nothing is charged.",
    "properties": {
     "currency": {
      "type": "string",
      "example": "IDR"
     },
     "before_per_month": {
      "type": "string"
     },
     "after_per_month": {
      "type": "string"
     },
     "delta_per_month": {
      "type": "string",
      "description": "`after` minus `before`; negative for a reduction."
     },
     "placeholder": {
      "type": "boolean"
     }
    }
   },
   "AddOnsOverview": {
    "type": "object",
    "description": "PAN-117. Body of GET /v1/billing/add-ons.",
    "properties": {
     "simulated": {
      "type": "boolean",
      "description": "Always true while payments are simulated."
     },
     "currency": {
      "type": "string"
     },
     "add_ons": {
      "type": "array",
      "description": "The add-on catalog with prices (placeholders) and which are sold.",
      "items": {
       "type": "object",
       "properties": {
        "key": {
         "type": "string"
        },
        "label": {
         "type": "string"
        },
        "unit": {
         "type": "string"
        },
        "max_quantity": {
         "type": "integer"
        },
        "purchasable": {
         "type": "boolean"
        },
        "price": {
         "$ref": "#/components/schemas/Price"
        }
       }
      }
     },
     "businesses": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/AddOnBusiness"
      }
     },
     "cost": {
      "$ref": "#/components/schemas/AddOnCost"
     }
    }
   },
   "AddOnsRequest": {
    "type": "object",
    "required": [
     "changes"
    ],
    "properties": {
     "changes": {
      "type": "array",
      "minItems": 1,
      "items": {
       "type": "object",
       "required": [
        "merchant_id",
        "key",
        "quantity"
       ],
       "properties": {
        "merchant_id": {
         "type": "string",
         "pattern": "^[A-Z0-9]{3,16}$",
         "description": "A business the caller owns."
        },
        "key": {
         "type": "string",
         "enum": [
          "extra_businesses",
          "extra_employee_accounts"
         ]
        },
        "quantity": {
         "type": "integer",
         "minimum": 0,
         "description": "The total extra quantity wanted for this business (0 removes it), not a delta."
        }
       }
      }
     },
     "keep": {
      "type": "object",
      "description": "What to keep when a decrease leaves too many businesses or employees (see the quote).",
      "properties": {
       "merchant_ids": {
        "type": "array",
        "items": {
         "type": "string",
         "pattern": "^[A-Z0-9]{3,16}$"
        }
       },
       "employee_ids": {
        "type": "array",
        "description": "Membership ids of the employees to keep.",
        "items": {
         "type": "string",
         "format": "uuid"
        }
       }
      }
     }
    }
   },
   "AddOnQuote": {
    "type": "object",
    "description": "PAN-117. Review of a change.",
    "properties": {
     "simulated": {
      "type": "boolean"
     },
     "rows": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "merchant_id": {
         "type": "string",
         "pattern": "^[A-Z0-9]{3,16}$"
        },
        "merchant_name": {
         "type": "string"
        },
        "key": {
         "type": "string"
        },
        "label": {
         "type": "string"
        },
        "now": {
         "type": "integer"
        },
        "after": {
         "type": "integer"
        },
        "direction": {
         "type": "string",
         "enum": [
          "increase",
          "decrease",
          "same"
         ]
        },
        "effective": {
         "type": "string",
         "enum": [
          "now",
          "period_end"
         ]
        },
        "effective_at": {
         "type": "string",
         "format": "date-time",
         "nullable": true
        }
       }
      }
     },
     "cost": {
      "$ref": "#/components/schemas/AddOnCost"
     },
     "needs_keep": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "kind": {
         "type": "string",
         "enum": [
          "businesses",
          "employees"
         ]
        },
        "merchant_id": {
         "type": "string",
         "pattern": "^[A-Z0-9]{3,16}$",
         "description": "Present for `employees`."
        },
        "merchant_name": {
         "type": "string"
        },
        "in_use": {
         "type": "integer"
        },
        "new_limit": {
         "type": "integer"
        },
        "required": {
         "type": "integer",
         "description": "Exactly this many must be kept."
        },
        "candidates": {
         "type": "array",
         "items": {
          "type": "object",
          "properties": {
           "id": {
            "type": "string",
            "format": "uuid",
            "description": "A business id, or an employee membership id."
           },
           "name": {
            "type": "string"
           },
           "code": {
            "type": "string",
            "description": "Business code (businesses only)."
           },
           "role": {
            "type": "string",
            "description": "Role (employees only)."
           }
          }
         }
        }
       }
      }
     }
    }
   },
   "AddOnsApplied": {
    "allOf": [
     {
      "$ref": "#/components/schemas/AddOnsOverview"
     },
     {
      "type": "object",
      "properties": {
       "charged": {
        "type": "boolean",
        "description": "Always false (simulated payment)."
       },
       "applied": {
        "$ref": "#/components/schemas/AddOnQuote"
       }
      }
     }
    ]
   },
   "BillingCheckoutRequest": {
    "type": "object",
    "required": [
     "tier"
    ],
    "properties": {
     "tier": {
      "type": "string",
      "enum": [
       "MONTHLY",
       "LIFETIME"
      ]
     }
    }
   },
   "StubCheckout": {
    "type": "object",
    "properties": {
     "checkout_id": {
      "type": "string",
      "example": "stubco_..."
     },
     "provider": {
      "type": "string",
      "example": "stub"
     },
     "tier": {
      "type": "string",
      "example": "MONTHLY"
     },
     "amount": {
      "type": "object",
      "properties": {
       "amount": {
        "type": "string",
        "example": "249000"
       },
       "currency": {
        "type": "string",
        "example": "IDR"
       },
       "period": {
        "type": "string",
        "enum": [
         "month",
         "one_time"
        ]
       }
      }
     },
     "expires_at": {
      "type": "string",
      "format": "date-time"
     },
     "confirm_url": {
      "type": "string",
      "example": "/v1/billing/checkout/confirm"
     }
    }
   },
   "BillingConfirmRequest": {
    "type": "object",
    "required": [
     "checkout_id"
    ],
    "properties": {
     "checkout_id": {
      "type": "string"
     }
    }
   },
   "BillingConfirmed": {
    "allOf": [
     {
      "$ref": "#/components/schemas/BillingStatus"
     },
     {
      "type": "object",
      "properties": {
       "checkout_id": {
        "type": "string"
       },
       "already_confirmed": {
        "type": "boolean"
       }
      }
     }
    ]
   },
   "StaffIDAvailability": {
    "type": "object",
    "required": [
     "available",
     "reason"
    ],
    "properties": {
     "available": {
      "type": "boolean"
     },
     "reason": {
      "type": "string",
      "nullable": true,
      "enum": [
       "required",
       "too_short",
       "too_long",
       "invalid_characters",
       "taken"
      ],
      "description": "Null when available."
     }
    }
   },
   "EmployeeChangePasswordRequest": {
    "type": "object",
    "required": [
     "current_password",
     "new_password"
    ],
    "properties": {
     "current_password": {
      "type": "string"
     },
     "new_password": {
      "type": "string",
      "minLength": 8,
      "maxLength": 128,
      "description": "Password rules: 8-128 characters and not equal to the employee ID (case-insensitive). Refused with 422 `validation_failed`, field `new_password`, issue `required`, `too_short`, `too_long` or `same_as_employee_code`."
     }
    }
   },
   "Invitation": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "role": {
      "type": "string",
      "enum": [
       "manager",
       "cashier",
       "kitchen",
       "custom"
      ]
     },
     "role_id": {
      "type": "string",
      "description": "PAN-89. Starter id or custom role uuid."
     },
     "role_name": {
      "type": "string",
      "description": "PAN-89."
     },
     "created_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "created_at + 30 minutes."
     },
     "accepted_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z",
      "nullable": true
     },
     "revoked_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z",
      "nullable": true
     },
     "invite_token": {
      "type": "string",
      "example": "inv_...",
      "description": "Returned ONCE, only in the create response. Put it in a link; whoever redeems it first (after Google sign-in) joins."
     },
     "invite_url": {
      "type": "string",
      "example": "https://app.example/join?token=inv_...",
      "description": "Convenience link, returned once together with invite_token."
     }
    }
   },
   "Menu": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "menu_name": {
      "type": "string",
      "example": "Main menu"
     }
    }
   },
   "MenuWrite": {
    "type": "object",
    "properties": {
     "menu_name": {
      "type": "string",
      "example": "Main menu"
     }
    },
    "required": [
     "menu_name"
    ]
   },
   "MenuItem": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "menu_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "recipe_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
      "nullable": true
     },
     "menu_item_name": {
      "type": "string",
      "example": "Latte"
     },
     "menu_item_desc": {
      "type": "string",
      "example": "Double espresso, steamed milk",
      "nullable": true
     },
     "menu_item_price": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "recipe_ingredient_count": {
      "type": "integer",
      "readOnly": true,
      "minimum": 0,
      "example": 3,
      "description": "Number of ingredient lines on the linked recipe. 0 when there is no recipe or the recipe has no lines. Returned on every menu-item response and ignored on writes."
     },
     "stock_status": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "untracked",
       "ok",
       "low",
       "out"
      ],
      "example": "low",
      "description": "Stock state of the recipe, from its worst line, with the same rules as `GET /v1/ingredients?status=`: `out` when any line's ingredient has stock_quantity <= 0, otherwise `low` when any has stock_quantity > 0 and <= its min_quantity (ingredients with no min_quantity are never low), otherwise `ok`. `untracked` when there is no recipe or the recipe has no lines. Returned on every menu-item response and ignored on writes."
     },
     "servings_available": {
      "type": "integer",
      "format": "int64",
      "readOnly": true,
      "nullable": true,
      "minimum": 0,
      "example": 12,
      "description": "Servings the current stock covers: the minimum over the recipe lines of floor(stock_quantity / quantity), never below 0. Plain stock (open orders are not reserved). Null when stock_status is `untracked`. Returned on every menu-item response and ignored on writes."
     },
     "recipe_cost": {
      "type": "string",
      "readOnly": true,
      "nullable": true,
      "pattern": "^\\d+\\.00$",
      "example": "4303.00",
      "x-roles": [
       "owner",
       "manager"
      ],
      "description": "PAN-73. Cost of one serving from the recipe: the sum over the recipe lines of quantity x the ingredient's current avg_unit_cost (the moving average kept by ingredient purchases), rounded half-up once on the total to whole rupiah and returned as a 2-dp decimal string. Null when there is no recipe, the recipe has no lines, or any line's ingredient has no known cost (avg_unit_cost 0, i.e. never bought); a partial sum is never returned. No price history: it always reflects the current averages. Only owners and managers get this key (list, get, create, PATCH and image confirm); for cashiers the key is omitted entirely. Ignored on writes."
     },
     "has_custom_charges": {
      "type": "boolean",
      "readOnly": true,
      "example": false,
      "description": "PAN-391. True when the item has its own setting (on, off or custom) for any non-deleted business charge, i.e. GET /v1/menu-items/{menuItemId}/charges has at least one row with mode other than default. Lets the item list show a \"Custom charges\" chip without one call per item. Returned on every menu-item response (list, get, create, PATCH and image confirm) and ignored on writes."
     },
     "image": {
      "type": "object",
      "properties": {
       "url": {
        "type": "string",
        "example": "https://r2.example/signed...",
        "description": "Short-lived signed GET URL (or a public CDN URL where the env has one)."
       },
       "content_type": {
        "type": "string",
        "example": "image/png"
       },
       "size_bytes": {
        "type": "integer",
        "example": 204800
       },
       "updated_at": {
        "type": "string",
        "format": "date-time",
        "example": "2026-10-04T08:30:00Z"
       }
      },
      "description": "Image metadata. The DB stores only the object key; the URL is built per request.",
      "nullable": true
     }
    }
   },
   "MenuItemWrite": {
    "type": "object",
    "properties": {
     "menu_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "recipe_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
      "nullable": true,
      "description": "Same-merchant recipe. On PATCH, null or \"\" clears the link and omitting it keeps the current link."
     },
     "menu_item_name": {
      "type": "string",
      "example": "Latte"
     },
     "menu_item_desc": {
      "type": "string",
      "example": "Double espresso, steamed milk"
     },
     "menu_item_price": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     }
    },
    "required": [
     "menu_id",
     "menu_item_name",
     "menu_item_price"
    ]
   },
   "IngredientCounts": {
    "type": "object",
    "description": "Ingredient counts for the Stock chips. They respect q, never status. The status=restock total is low + out.",
    "properties": {
     "all": {
      "type": "integer",
      "example": 42
     },
     "low": {
      "type": "integer",
      "example": 3,
      "description": "stock_quantity > 0 and at or under min_quantity."
     },
     "out": {
      "type": "integer",
      "example": 2,
      "description": "stock_quantity <= 0."
     }
    },
    "required": [
     "all",
     "low",
     "out"
    ]
   },
   "Ingredient": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "ingredient_name": {
      "type": "string",
      "example": "Coffee beans"
     },
     "unit": {
      "type": "string",
      "example": "g",
      "description": "Stock unit. One of pcs, g, kg, mg, ml, l, except on a legacy ingredient (see unit_locked) whose stored unit is a value migration 0026 did not map."
     },
     "unit_locked": {
      "type": "boolean",
      "example": true,
      "description": "PAN-95. True when the unit cannot be changed: a PATCH that changes it is 422 unit_locked. False only on legacy ingredients whose stored unit is not one of the six; the first PATCH that sets one of the six changes it and locks it. New ingredients are locked from the start."
     },
     "min_quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "5.000",
      "nullable": true,
      "description": "Low-stock threshold. Null means this ingredient is not checked for low stock. Decimal string, up to 3 dp. Zero is allowed."
     },
     "par_quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "20.000",
      "nullable": true,
      "description": "Restock target for the shopping list. Null means no target. Decimal string, up to 3 dp; at least min_quantity when both are set. It does not change the low/out rules. The app suggests buying par_quantity - stock_quantity, or min_quantity - stock_quantity when there is no target."
     },
     "last_supplier": {
      "type": "string",
      "maxLength": 255,
      "example": "Toko Beras Jaya",
      "nullable": true,
      "description": "Read-only. The supplier on the ingredient's most recent stock-in (expense ingredient line) that names one: latest expense incurred_on, then latest created_at. Stock-ins with no supplier are skipped; null when no stock-in names a supplier. Free text from the expense; there is no suppliers list."
     },
     "stock_quantity": {
      "type": "string",
      "pattern": "^-?\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Decimal string, up to 3 dp. Can go below zero (for example after a write-off or a sale with too little stock)."
     },
     "avg_unit_cost": {
      "type": "string",
      "example": "100.0000",
      "description": "PAN-88. Only with the `costs.view` permission; the key is absent otherwise."
     },
     "last_unit_price": {
      "type": "string",
      "nullable": true,
      "example": "10.0000",
      "description": "PAN-220. Unit price of the latest non-voided stock-in line (corrected values), as a decimal string per the ingredient's stock unit (e.g. per g when the purchase was entered in kg; the stored stock-unit quantity is used). Null when the ingredient has never been bought. Only with `costs.view`; the key is absent otherwise (do not send null without the permission — clients use containsKey)."
     },
     "last_purchased_on": {
      "type": "string",
      "format": "date",
      "nullable": true,
      "example": "2026-10-08",
      "description": "PAN-220. Business date (YYYY-MM-DD, expense `incurred_on`) of that latest non-voided stock-in. Null when never bought. Only with `costs.view`; the key is absent otherwise."
     },
     "last_audited_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z",
      "nullable": true
     },
     "image": {
      "type": "object",
      "properties": {
       "url": {
        "type": "string",
        "example": "https://r2.example/signed...",
        "description": "Short-lived signed GET URL (or a public CDN URL where the env has one)."
       },
       "content_type": {
        "type": "string",
        "example": "image/png"
       },
       "size_bytes": {
        "type": "integer",
        "example": 204800
       },
       "updated_at": {
        "type": "string",
        "format": "date-time",
        "example": "2026-10-04T08:30:00Z"
       }
      },
      "description": "Image metadata. The DB stores only the object key; the URL is built per request.",
      "nullable": true
     }
    }
   },
   "ShoppingListItem": {
    "type": "object",
    "description": "PAN-373. One saved shopping list row.",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true,
      "description": "Set for an ingredient row; null for free text."
     },
     "name": {
      "type": "string",
      "example": "Tisu",
      "description": "The ingredient's current name for an ingredient row, otherwise the free text."
     },
     "quantity": {
      "type": "string",
      "nullable": true,
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "2.000"
     },
     "unit": {
      "type": "string",
      "nullable": true,
      "example": "pak"
     },
     "note": {
      "type": "string",
      "nullable": true,
      "example": "Yang besar"
     },
     "bought": {
      "type": "boolean"
     },
     "bought_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     }
    },
    "required": [
     "id",
     "ingredient_id",
     "name",
     "quantity",
     "unit",
     "note",
     "bought",
     "bought_at",
     "created_at",
     "updated_at"
    ]
   },
   "ShoppingListItemCreate": {
    "type": "object",
    "properties": {
     "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "description": "An ingredient of this business. Send this or name, not both."
     },
     "name": {
      "type": "string",
      "maxLength": 120,
      "description": "Free text item. Send this or ingredient_id, not both."
     },
     "quantity": {
      "type": "string",
      "nullable": true,
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "description": "Optional, greater than 0, up to 3 decimals."
     },
     "unit": {
      "type": "string",
      "nullable": true,
      "maxLength": 32,
      "description": "Optional free text unit. An ingredient row without one takes the ingredient's unit."
     },
     "note": {
      "type": "string",
      "nullable": true,
      "maxLength": 200
     }
    }
   },
   "ShoppingListItemPatch": {
    "type": "object",
    "properties": {
     "name": {
      "type": "string",
      "maxLength": 120,
      "description": "Free text rows only."
     },
     "quantity": {
      "type": "string",
      "nullable": true,
      "pattern": "^\\d+(\\.\\d{1,3})?$"
     },
     "unit": {
      "type": "string",
      "nullable": true,
      "maxLength": 32
     },
     "note": {
      "type": "string",
      "nullable": true,
      "maxLength": 200
     },
     "bought": {
      "type": "boolean"
     }
    }
   },
   "IngredientWrite": {
    "type": "object",
    "properties": {
     "ingredient_name": {
      "type": "string",
      "example": "Coffee beans"
     },
     "unit": {
      "type": "string",
      "enum": [
       "pcs",
       "g",
       "kg",
       "mg",
       "ml",
       "l"
      ],
      "example": "g",
      "description": "PAN-95. One of pcs, g, kg, mg, ml, l (case and surrounding spaces are ignored, so KG is stored as kg); anything else is 422 validation_failed on field unit, on create and on PATCH. On PATCH, sending the current unit back is always accepted (a legacy value included) and changes nothing. A different unit is 422 unit_locked while unit_locked is true; on a legacy ingredient (unit_locked false) one of the six is set once and then locks."
     },
     "min_quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "5.000",
      "nullable": true,
      "description": "Optional low-stock threshold. On create, omit or null leaves it unset. On patch, omit leaves it unchanged and null clears it."
     },
     "par_quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "20.000",
      "nullable": true,
      "description": "Optional restock target, same format and omit/null rules as min_quantity. Must be at least min_quantity when both are set (422 on par_quantity)."
     }
    },
    "required": [
     "ingredient_name",
     "unit"
    ],
    "description": "stock_quantity and avg_unit_cost are never written directly; they change only through purchases, sales, waste and audits. min_quantity and par_quantity are the only stock-related fields this body may set. last_supplier is read-only."
   },
   "StockMovement": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "change_qty": {
      "type": "string",
      "example": "-18.000"
     },
     "reason": {
      "type": "string",
      "enum": [
       "purchase",
       "sale",
       "waste",
       "audit"
      ]
     },
     "unit_cost": {
      "type": "string",
      "example": "100.0000",
      "nullable": true,
      "description": "Cost per stock unit for this movement. Omitted (not null) when the caller lacks costs.view (PAN-201)."
     },
     "short": {
      "type": "string",
      "example": "1500.000",
      "description": "PAN-85. For a sale, how much of the need stock could not cover (change_qty is what was deducted, so a sale can be 0.000). '0.000' for every other movement."
     },
     "reversal_of": {
      "type": "string",
      "format": "uuid",
      "nullable": true,
      "description": "PAN-87. Set on the sale movement that undoes a served item (positive change_qty, same unit_cost); it is the id of the sale movement it reverses. Null otherwise."
     },
     "created_by_name": {
      "type": "string",
      "nullable": true,
      "description": "PAN-156/224, PAN-343. Who logged the movement (waste), copied at write time: code staff of this business use the staff login name; owners and invited Google members use the directory display name, else its email. A blank stored name with created_by_user_id set is filled at read time from that account's membership of this business (not written back); a deleted staff login, a member who left, or another business's account stays null, never the owner. New rows never use the literal 'Unknown'."
     },
     "created_by_user_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true,
      "description": "PAN-224. Acting account id for the movement. Null on legacy rows."
     },
     "negative_override": {
      "type": "boolean",
      "description": "PAN-209. True when this movement was written under stock.override (confirm_negative_stock)."
     },
     "occurred_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     }
    }
   },
   "WasteWrite": {
    "type": "object",
    "properties": {
     "quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Decimal string, up to 3 dp."
     },
     "note": {
      "type": "string",
      "example": "Spilled",
      "description": "Stored on the entry since PAN-156 (up to 2000 chars)."
     },
     "waste_reason": {
      "type": "string",
      "maxLength": 64,
      "example": "spoiled",
      "description": "Optional short reason (PAN-156)."
     }
    },
    "required": [
     "quantity"
    ]
   },
   "RecipeLine": {
    "type": "object",
    "properties": {
     "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "ingredient_name": {
      "type": "string",
      "readOnly": true,
      "example": "Milk",
      "description": "Joined from ingredients; returned on every recipe response and ignored on writes."
     },
     "unit": {
      "type": "string",
      "example": "ml",
      "description": "Response: the ingredient stock unit, as in GET /v1/ingredients; quantity is in that unit. Request (PAN-95): optional unit the line is entered in, one of pcs, g, kg, mg, ml, l in the ingredient family (g/kg/mg, ml/l, or pcs alone). Omitted or null means the stock unit. A unit of another family is 422 unit_family_mismatch; any other value is 422 validation_failed. The server converts quantity to the stock unit with exact decimal math and stores that, so cost, servings, stock checks and serving use the converted quantity. Sending a response line back unchanged is safe."
     },
     "stock_quantity": {
      "type": "string",
      "readOnly": true,
      "pattern": "^-?\\d+(\\.\\d{1,3})?$",
      "example": "1500.000",
      "description": "The ingredient's current stock, the same decimal string as `stock_quantity` in `GET /v1/ingredients` (up to 3 dp; it can go below zero after a write-off). Returned on every recipe response and ignored on writes."
     },
     "quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Request: the amount in unit (or in the stock unit when unit is omitted), up to 3 dp. Response: the converted amount in the ingredient stock unit (unit), 3 dp. A conversion that is not exact is rounded half up at 3 dp (1.5 mg to g is 0.002; 0.0005 kg is 0.001); one that rounds to 0.000 is 422 validation_failed on quantity."
     },
     "line_unit": {
      "type": "string",
      "readOnly": true,
      "example": "g",
      "description": "PAN-95. The unit the line was entered in (the stock unit when none was sent). Ignored on writes."
     },
     "line_quantity": {
      "type": "string",
      "readOnly": true,
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "250.000",
      "description": "PAN-95. The quantity as entered, in line_unit, 3 dp. Ignored on writes."
     }
    },
    "required": [
     "ingredient_id",
     "quantity"
    ]
   },
   "Recipe": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "recipe_name": {
      "type": "string",
      "example": "Latte"
     },
     "ingredients": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/RecipeLine"
      }
     },
     "used_by_items": {
      "type": "integer",
      "minimum": 0,
      "readOnly": true,
      "example": 2,
      "description": "How many of the merchant's menu items use this recipe (`recipe_id`). 0 when none."
     },
     "recipe_cost": {
      "type": "string",
      "readOnly": true,
      "nullable": true,
      "pattern": "^\\d+\\.00$",
      "example": "300.00",
      "x-permissions": [
       "costs.view"
      ],
      "description": "PAN-142. Cost of one serving of this recipe: the sum of quantity x the ingredient's current avg_unit_cost, rounded half-up to whole rupiah, as a 2-dp string. Null when the recipe has no lines or any ingredient has no known cost. Only callers with costs.view get the key (list, get, create, PUT); otherwise it is omitted. Ignored on writes."
     }
    }
   },
   "RecipeWrite": {
    "type": "object",
    "properties": {
     "recipe_name": {
      "type": "string",
      "example": "Latte"
     },
     "ingredients": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/RecipeLine"
      }
     }
    },
    "required": [
     "recipe_name",
     "ingredients"
    ]
   },
   "OrderItemWrite": {
    "type": "object",
    "properties": {
     "menu_item_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "quantity": {
      "type": "integer",
      "minimum": 1,
      "example": 2
     },
     "note": {
      "type": "string",
      "example": "Less sugar"
     }
    },
    "required": [
     "menu_item_id",
     "quantity"
    ]
   },
   "OrderItem": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "menu_item_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "round_no": {
      "type": "integer",
      "example": 1
     },
     "quantity": {
      "type": "integer"
     },
     "unit_price": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "status": {
      "type": "string",
      "enum": [
       "placed",
       "preparing",
       "served",
       "cancelled"
      ]
     },
     "note": {
      "type": "string",
      "example": "Less sugar",
      "nullable": true
     },
     "added_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     },
     "short_quantity": {
      "type": "integer",
      "minimum": 0,
      "description": "PAN-85. How many of quantity stock could not cover (ordered - can make). 0 when nothing is short. Recorded when a short round is processed, and replaced by the real numbers when the item is served."
     },
     "short_ingredients": {
      "type": "array",
      "description": "PAN-85. The materials the item could not get in full; empty when nothing is short.",
      "items": {
       "$ref": "#/components/schemas/ShortIngredient"
      }
     },
     "est_cost_full": {
      "type": "string",
      "nullable": true,
      "example": "700.00",
      "description": "PAN-86. Owner and manager only; the key is absent for cashier and kitchen. Ingredient cost of the full quantity at avg_unit_cost, a 2 dp string, set when the item is confirmed (a snapshot). Null while the item is not confirmed, has no recipe, or a material has no known cost (avg_unit_cost 0)."
     },
     "est_cost_adjusted": {
      "type": "string",
      "nullable": true,
      "example": "625.00",
      "description": "PAN-86. Owner and manager only. Ingredient cost of what stock covered (per material, so it is below est_cost_full only when the item is short), set at confirm. Same null rules as est_cost_full."
     },
     "cost_actual": {
      "type": "string",
      "nullable": true,
      "example": "710.00",
      "description": "PAN-86. Owner and manager only. Sum of the deducted quantity x unit cost of the item's sale stock movements, set when the item is served; the reports value cost of sales from the same movements. Null until served, or when nothing was deducted at a known cost."
     },
     "ready_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "PAN-87. When the line was ticked Ready (it stays preparing). Null when not ready or undone. Cleared when the line is cancelled."
     },
     "ready_by_name": {
      "type": "string",
      "nullable": true,
      "example": "Dewi",
      "description": "PAN-87, PAN-105, PAN-343. The name of who ticked it Ready, copied at tick time (no staff id), so it stays when that person is removed or renamed. Code staff of this business use the staff login name; owners and invited Google members use the directory display name, else its email. Another business's member is never stored. Null when not ready or undone."
     },
     "served_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "PAN-87. When the line was served. Null while not served (also null on lines served before 2026-10-16)."
     },
     "served_by_name": {
      "type": "string",
      "nullable": true,
      "example": "Dewi",
      "description": "PAN-87, PAN-105, PAN-343. The name of who served it, copied at serve time (no staff id; a close serves leftover lines as the person closing). Code staff of this business use the staff login name; owners and invited Google members use the directory display name, else its email. Another business's member is never stored. Null when not served or undone."
     },
     "charges": {
      "type": "array",
      "description": "PAN-391 PR2. This line's share of each bill charge: priced live while the order is open, as stored at close afterwards. Empty for cancelled lines, for lines a charge does not cover, and on orders closed before per-line charges existed (their bill amounts stay on the order's charges). A charge's line amounts always add up to its amount on the order.",
      "items": {
       "$ref": "#/components/schemas/LineCharge"
      }
     }
    }
   },
   "LineCharge": {
    "type": "object",
    "description": "PAN-391 PR2. One order line's share of one bill charge.",
    "properties": {
     "charge_id": {
      "type": "string",
      "format": "uuid"
     },
     "mode": {
      "type": "string",
      "enum": [
       "default",
       "on",
       "custom"
      ],
      "description": "default = the order's snapshot rate; on = an applies_to=selected_items charge the item turned on; custom = the item's own type and value."
     },
     "type": {
      "type": "string",
      "enum": [
       "percent",
       "fixed"
      ]
     },
     "value": {
      "type": "string",
      "example": "10.00",
      "description": "The rate or amount this line used. A custom fixed value is per unit."
     },
     "amount": {
      "type": "string",
      "example": "2100.00",
      "description": "The line's amount in the currency minor unit. Lines are priced at full precision (percent base = qty x unit price + this line's share of the apply_after charge; a bill-wide fixed charge spread by qty x unit price), each charge is rounded once on the bill, and that rounded total is handed back to the lines by largest remainder."
     }
    },
    "required": [
     "charge_id",
     "mode",
     "type",
     "value",
     "amount"
    ]
   },
   "ShortIngredient": {
    "type": "object",
    "properties": {
     "ingredient_id": {
      "type": "string",
      "format": "uuid"
     },
     "ingredient_name": {
      "type": "string",
      "example": "Chicken"
     },
     "unit": {
      "type": "string",
      "example": "g"
     },
     "needed": {
      "type": "string",
      "example": "10000.000"
     },
     "deducted": {
      "type": "string",
      "example": "8500.000",
      "description": "What stock gave (planned at confirm, actual once served)."
     },
     "short": {
      "type": "string",
      "example": "1500.000",
      "description": "needed - deducted."
     }
    }
   },
   "OrderCreate": {
    "type": "object",
    "properties": {
     "menu_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
      "nullable": true,
      "description": "Optional. Menus are categories; an order may contain items from several menus."
     },
     "table_label": {
      "type": "string",
      "example": "T7",
      "nullable": true
     },
     "items": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/OrderItemWrite"
      },
      "description": "Optional first round. Each item may belong to any menu of the merchant."
     }
    }
   },
   "OrderAddRound": {
    "type": "object",
    "properties": {
     "items": {
      "type": "array",
      "minItems": 1,
      "items": {
       "$ref": "#/components/schemas/OrderItemWrite"
      }
     }
    },
    "required": [
     "items"
    ],
    "description": "Adds a new round (round_no = previous max + 1). unit_price is copied from the menu item at this moment. Any menu item of the merchant may be added."
   },
   "OrderItemUpdate": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "enum": [
       "preparing",
       "served",
       "cancelled"
      ]
     },
     "quantity": {
      "type": "integer",
      "minimum": 1,
      "description": "New quantity. Only while the item status is placed; otherwise 409 item_not_editable."
     },
     "note": {
      "type": "string",
      "nullable": true,
      "description": "Replaces the note. Null clears it. Only while the item status is placed."
     },
     "reason": {
      "type": "string",
      "example": "out_of_stock",
      "maxLength": 32,
      "description": "Stored as cancel_reason when status=cancelled."
     },
     "ready": {
      "type": "boolean",
      "description": "PAN-87. true ticks the line Ready (only while it is preparing; the time and member are recorded; repeating keeps the first tick). false clears the tick. Roles: owner, manager, kitchen. Send it on its own or together with served."
     },
     "served": {
      "type": "boolean",
      "description": "PAN-87. true serves a line that is ready (409 item_not_ready otherwise) and deducts its stock. false returns a served line to preparing and reverses exactly the stock it deducted (a reversal movement with reversal_of; its ready tick stays). Roles: owner, manager, cashier."
     }
    },
    "description": "At least one of status, quantity, note, ready or served is required. quantity and note can be changed only while the item is placed (409 item_not_editable). Serving an item writes the stock movements (one per recipe ingredient) in the same transaction. ready and served cannot be combined with status, quantity, note or reason (422), except ready with served in one call (ready is applied first). The ready and served ticks are idempotent (repeating returns 200 with the current line). Role per field (403 forbidden otherwise): ready - owner, manager, kitchen; served, status, quantity, note, reason - owner, manager, cashier."
   },
   "Charge": {
    "type": "object",
    "description": "PAN-129. A bill charge such as tax or service, made by the business.",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "name": {
      "type": "string",
      "maxLength": 40,
      "example": "Service"
     },
     "type": {
      "type": "string",
      "enum": [
       "percent",
       "fixed"
      ]
     },
     "value": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "5.00",
      "description": "Percent (0.01-100) or a fixed amount, 2 dp decimal string."
     },
     "receipt_label": {
      "type": "string",
      "nullable": true,
      "maxLength": 40,
      "example": "Service 5%"
     },
     "apply_after": {
      "type": "string",
      "format": "uuid",
      "nullable": true,
      "description": "The charge this one is calculated on top of (base = subtotal + that charge's amount)."
     },
     "default_on": {
      "type": "boolean",
      "description": "Added to every new order unless the cashier removes it; false means the cashier may add it."
     },
     "cashier_can_remove": {
      "type": "boolean",
      "description": "False means only the owner or a manager may remove it at confirm."
     },
     "active": {
      "type": "boolean",
      "description": "False pauses the charge (not offered on new orders)."
     },
     "sort_order": {
      "type": "integer"
     },
     "kind": {
      "type": "string",
      "nullable": true,
      "enum": [
       "revenue",
       "tax",
       "collected_for_others",
       null
      ],
      "description": "PAN-391. revenue (the business keeps it, counts in sales), tax (for the government, outside sales) or collected_for_others (tips or a fee passed on in full, outside sales). Null = Unclassified: a charge made before kind existed; the app asks the owner once to pick one. A change applies to new orders only; orders keep the kind they took."
     },
     "note": {
      "type": "string",
      "nullable": true,
      "maxLength": 200,
      "description": "PAN-391. The owner's own tooltip note (trimmed, null when none). It is live, so an edit shows everywhere at once, past orders included. Never copied onto orders and never printed on receipts."
     },
     "used_on_orders": {
      "type": "boolean",
      "description": "PAN-391. True when an order has taken this charge, or when a deleted charge still applies after it (kept for past orders). DELETE then hides it (soft, header `Panly-Charge-Delete: soft`) instead of removing it for good; false means DELETE is hard."
     },
     "applies_to": {
      "type": "string",
      "enum": [
       "all",
       "selected_items"
      ],
      "description": "PAN-391 PR2. all: every item unless the item turns it off. selected_items: only items that turn it on or set a custom rate (an alcohol tax, a packaging fee). Per-item settings: GET/PUT /v1/menu-items/{menuItemId}/charges."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     }
    },
    "required": [
     "id",
     "name",
     "type",
     "value",
     "receipt_label",
     "apply_after",
     "default_on",
     "cashier_can_remove",
     "active",
     "sort_order",
     "kind",
     "note",
     "applies_to",
     "used_on_orders",
     "created_at",
     "updated_at"
    ]
   },
   "ChargeWrite": {
    "type": "object",
    "properties": {
     "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 40
     },
     "type": {
      "type": "string",
      "enum": [
       "percent",
       "fixed"
      ]
     },
     "value": {
      "type": "string",
      "example": "10",
      "description": "Decimal string (a JSON number is accepted too), at most 2 dp."
     },
     "receipt_label": {
      "type": "string",
      "nullable": true,
      "maxLength": 40
     },
     "apply_after": {
      "type": "string",
      "format": "uuid",
      "nullable": true
     },
     "default_on": {
      "type": "boolean",
      "default": true
     },
     "cashier_can_remove": {
      "type": "boolean",
      "default": true
     },
     "active": {
      "type": "boolean",
      "default": true
     },
     "sort_order": {
      "type": "integer"
     },
     "kind": {
      "type": "string",
      "enum": [
       "revenue",
       "tax",
       "collected_for_others"
      ],
      "description": "PAN-391. Required on create (422 validation_failed when missing or another value; no default). On PATCH it may be changed but not set back to null; the change applies to new orders only."
     },
     "note": {
      "type": "string",
      "nullable": true,
      "maxLength": 200,
      "description": "PAN-391. Optional owner note, trimmed; empty or null clears it. More than 200 characters is 422."
     },
     "applies_to": {
      "type": "string",
      "enum": [
       "all",
       "selected_items"
      ],
      "default": "all",
      "description": "PAN-391 PR2. Omit to keep (all on create). Applies to orders confirmed afterwards."
     }
    }
   },
   "ItemCharge": {
    "type": "object",
    "description": "PAN-391 PR2. One business charge as a menu item sees it.",
    "properties": {
     "charge_id": {
      "type": "string",
      "format": "uuid"
     },
     "name": {
      "type": "string"
     },
     "kind": {
      "type": "string",
      "nullable": true,
      "enum": [
       "revenue",
       "tax",
       "collected_for_others",
       null
      ]
     },
     "note": {
      "type": "string",
      "nullable": true,
      "maxLength": 200,
      "description": "PAN-391. The business charge's owner tooltip note, the same live field as `note` on GET /v1/charges (null when none). Never per item."
     },
     "applies_to": {
      "type": "string",
      "enum": [
       "all",
       "selected_items"
      ]
     },
     "type": {
      "type": "string",
      "enum": [
       "percent",
       "fixed"
      ]
     },
     "value": {
      "type": "string",
      "example": "10.00"
     },
     "active": {
      "type": "boolean"
     },
     "mode": {
      "type": "string",
      "enum": [
       "default",
       "on",
       "off",
       "custom"
      ]
     },
     "custom_type": {
      "type": "string",
      "nullable": true,
      "enum": [
       "percent",
       "fixed",
       null
      ]
     },
     "custom_value": {
      "type": "string",
      "nullable": true,
      "description": "Per unit when custom_type is fixed."
     },
     "applies": {
      "type": "boolean",
      "description": "Whether a line of this item gets the charge when the order has it."
     }
    },
    "required": [
     "charge_id",
     "name",
     "kind",
     "note",
     "applies_to",
     "type",
     "value",
     "active",
     "mode",
     "custom_type",
     "custom_value",
     "applies"
    ]
   },
   "ItemChargeWrite": {
    "type": "object",
    "properties": {
     "charge_id": {
      "type": "string",
      "format": "uuid"
     },
     "mode": {
      "type": "string",
      "enum": [
       "default",
       "on",
       "off",
       "custom"
      ]
     },
     "type": {
      "type": "string",
      "enum": [
       "percent",
       "fixed"
      ],
      "description": "Only with mode custom (required there)."
     },
     "value": {
      "type": "string",
      "description": "Only with mode custom (required there). Percent 0.01 to 100; fixed > 0, per unit."
     }
    },
    "required": [
     "charge_id",
     "mode"
    ]
   },
   "OrderQuote": {
    "type": "object",
    "description": "PAN-391 PR2. What the order would store for this cart (POST /v1/orders/quote) or for this open order after the quoted change (POST /v1/orders/{orderId}/quote). Nothing is written.",
    "properties": {
     "currency": {
      "type": "string",
      "example": "IDR"
     },
     "order_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true,
      "description": "The quoted open order; null for a cart quote."
     },
     "items": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "order_item_id": {
         "type": "string",
         "format": "uuid",
         "nullable": true,
         "description": "The order line this is; null for a cart line or a quoted new line."
        },
        "menu_item_id": {
         "type": "string",
         "format": "uuid"
        },
        "quantity": {
         "type": "integer"
        },
        "unit_price": {
         "type": "string"
        },
        "subtotal": {
         "type": "string"
        },
        "charges": {
         "type": "array",
         "items": {
          "$ref": "#/components/schemas/LineCharge"
         }
        }
       },
       "required": [
        "order_item_id",
        "menu_item_id",
        "quantity",
        "unit_price",
        "subtotal",
        "charges"
       ]
      }
     },
     "charges": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "charge_id": {
         "type": "string",
         "format": "uuid"
        },
        "name": {
         "type": "string"
        },
        "receipt_label": {
         "type": "string",
         "nullable": true
        },
        "kind": {
         "type": "string",
         "nullable": true,
         "enum": [
          "revenue",
          "tax",
          "collected_for_others",
          null
         ]
        },
        "applies_to": {
         "type": "string",
         "enum": [
          "all",
          "selected_items"
         ]
        },
        "type": {
         "type": "string",
         "enum": [
          "percent",
          "fixed"
         ]
        },
        "value": {
         "type": "string"
        },
        "removed": {
         "type": "boolean"
        },
        "on_some_items": {
         "type": "boolean"
        },
        "amount": {
         "type": "string"
        }
       },
       "required": [
        "charge_id",
        "name",
        "receipt_label",
        "kind",
        "applies_to",
        "type",
        "value",
        "removed",
        "on_some_items",
        "amount"
       ]
      }
     },
     "subtotal": {
      "type": "string"
     },
     "charges_total": {
      "type": "string"
     },
     "total": {
      "type": "string"
     }
    },
    "required": [
     "currency",
     "order_id",
     "items",
     "charges",
     "subtotal",
     "charges_total",
     "total"
    ]
   },
   "OrderCharge": {
    "type": "object",
    "description": "PAN-129. A charge on one order, copied from the charge when the order took it.",
    "properties": {
     "charge_id": {
      "type": "string",
      "format": "uuid"
     },
     "name": {
      "type": "string"
     },
     "receipt_label": {
      "type": "string",
      "nullable": true
     },
     "type": {
      "type": "string",
      "enum": [
       "percent",
       "fixed"
      ]
     },
     "value": {
      "type": "string",
      "example": "10.00"
     },
     "apply_after": {
      "type": "string",
      "format": "uuid",
      "nullable": true
     },
     "kind": {
      "type": "string",
      "nullable": true,
      "enum": [
       "revenue",
       "tax",
       "collected_for_others",
       null
      ],
      "description": "PAN-391. The charge's kind when this order took it (null = Unclassified, e.g. orders from before kind existed). Never changed by a later edit of the charge. The owner note is not on orders."
     },
     "applies_to": {
      "type": "string",
      "enum": [
       "all",
       "selected_items"
      ],
      "description": "PAN-391 PR2. The charge's applies_to when the order took it."
     },
     "on_some_items": {
      "type": "boolean",
      "description": "PAN-391 PR2. True when the charge covered some but not all of the non-cancelled lines (receipt note \"on some items\"). False on orders closed before per-line charges existed."
     },
     "amount": {
      "type": "string",
      "example": "3000.00",
      "description": "PAN-391 PR2. The sum of this charge's line amounts (items[].charges): each line priced at full precision, rounded once on the bill to the currency minor unit (IDR whole rupiah, others 2 dp). Live while the order is open; once closed, the amount stored at close. 0 when removed."
     },
     "removed": {
      "type": "boolean"
     },
     "removed_by_name": {
      "type": "string",
      "nullable": true,
      "example": "Sari",
      "description": "PAN-129, PAN-343. The name of who removed the charge at confirm, copied at that time (no staff id). Code staff of this business use the staff login name; owners and invited Google members use the directory display name, else its email. Another business's member is never stored. A later confirm that keeps the charge removed reuses this snapshot. Null when the charge is not removed, or when nobody can be named."
     },
     "removed_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true
     }
    },
    "required": [
     "charge_id",
     "name",
     "receipt_label",
     "type",
     "value",
     "apply_after",
     "amount",
     "removed",
     "removed_by_name",
     "removed_at"
    ]
   },
   "SplitRequest": {
    "type": "object",
    "required": [
     "mode",
     "parts"
    ],
    "properties": {
     "mode": {
      "type": "string",
      "enum": [
       "by_item",
       "by_amount"
      ]
     },
     "parts": {
      "type": "array",
      "minItems": 2,
      "maxItems": 50,
      "items": {
       "type": "object",
       "properties": {
        "items": {
         "type": "array",
         "description": "by_item only. Quantities of order lines this part takes.",
         "items": {
          "type": "object",
          "required": [
           "order_item_id",
           "quantity"
          ],
          "properties": {
           "order_item_id": {
            "type": "string",
            "format": "uuid"
           },
           "quantity": {
            "type": "integer",
            "minimum": 1
           }
          }
         }
        },
        "amount": {
         "type": "string",
         "description": "by_amount only. Decimal string or number; all amounts must add up to the order total.",
         "example": "50000"
        }
       }
      }
     }
    }
   },
   "Split": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "order_id": {
      "type": "string",
      "format": "uuid"
     },
     "mode": {
      "type": "string",
      "enum": [
       "by_item",
       "by_amount"
      ]
     },
     "currency": {
      "type": "string",
      "example": "IDR"
     },
     "subtotal": {
      "type": "string",
      "example": "100000.00"
     },
     "charges_total": {
      "type": "string",
      "example": "10000.00"
     },
     "total": {
      "type": "string",
      "example": "110000.00"
     },
     "locked": {
      "type": "boolean",
      "description": "True once any part is paid (a re-split is then 409 split_locked)."
     },
     "created_by_name": {
      "type": "string",
      "nullable": true,
      "description": "PAN-135, PAN-343. The name of who created this split, copied at write time (no staff id). Code staff of this business use the staff login name; owners and invited Google members use the directory display name, else its email. Another business's member is never stored. Null when nobody can be named."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "parts": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/SplitPart"
      }
     }
    }
   },
   "SplitPart": {
    "type": "object",
    "properties": {
     "part_no": {
      "type": "integer",
      "example": 1
     },
     "status": {
      "type": "string",
      "enum": [
       "unpaid",
       "paid"
      ]
     },
     "subtotal": {
      "type": "string",
      "example": "50000.00"
     },
     "charges_total": {
      "type": "string",
      "example": "5000.00"
     },
     "total": {
      "type": "string",
      "example": "55000.00"
     },
     "items": {
      "type": "array",
      "description": "by_item lines of this part (empty for by_amount).",
      "items": {
       "type": "object",
       "properties": {
        "order_item_id": {
         "type": "string",
         "format": "uuid"
        },
        "quantity": {
         "type": "integer"
        },
        "unit_price": {
         "type": "string",
         "example": "25000.00"
        },
        "amount": {
         "type": "string",
         "description": "unit_price x quantity",
         "example": "50000.00"
        }
       }
      }
     },
     "method": {
      "type": "string",
      "enum": [
       "cash",
       "qris",
       "card",
       "transfer"
      ],
      "nullable": true
     },
     "cash_received": {
      "type": "string",
      "nullable": true
     },
     "change": {
      "type": "string",
      "nullable": true
     },
     "reference": {
      "type": "string",
      "nullable": true
     },
     "paid_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true
     },
     "paid_by_name": {
      "type": "string",
      "nullable": true,
      "description": "PAN-140, PAN-343. The name of who paid this part, copied at write time (no staff id). Code staff of this business use the staff login name; owners and invited Google members use the directory display name, else its email. Another business's member is never stored. Null while the part is unpaid, or when nobody can be named."
     }
    }
   },
   "SplitPartPayRequest": {
    "type": "object",
    "required": [
     "method"
    ],
    "properties": {
     "method": {
      "type": "string",
      "enum": [
       "cash",
       "qris",
       "card",
       "transfer"
      ]
     },
     "cash_received": {
      "type": "string",
      "description": "Required for cash, >= the part total. Decimal string or number."
     },
     "reference": {
      "type": "string",
      "maxLength": 255,
      "description": "Optional, for qris, card and transfer."
     }
    }
   },
   "SplitPartPayment": {
    "type": "object",
    "properties": {
     "split": {
      "$ref": "#/components/schemas/Split"
     },
     "part": {
      "$ref": "#/components/schemas/SplitPart"
     },
     "change": {
      "type": "string",
      "nullable": true,
      "description": "cash_received - total for cash, else null."
     },
     "order_paid": {
      "type": "boolean",
      "description": "True when this payment paid the last unpaid part. The order is then completed (PAN-140): status closed, with paid_at and closed_at set."
     }
    }
   },
   "Order": {
    "type": "object",
    "properties": {
     "currency": {
      "type": "string",
      "example": "IDR",
      "description": "PAN-90. ISO 4217 code of the business currency. Amounts stay 2 dp decimal strings."
     },
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "order_no": {
      "type": "integer",
      "example": 12,
      "description": "Per-merchant order number, assigned when the order is created. Unique per merchant and increasing; gaps are possible (a create that fails or is rolled back uses up its number, PAN-161)."
     },
     "menu_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
      "nullable": true
     },
     "billing_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
      "nullable": true
     },
     "table_label": {
      "type": "string",
      "example": "T7",
      "nullable": true
     },
     "status": {
      "type": "string",
      "enum": [
       "open",
       "closed",
       "cancelled"
      ]
     },
     "ordered_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     },
     "paid_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "Set when the order is paid in full: on close, or when the last part of its split is paid, which also closes the order (PAN-140)."
     },
     "closed_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z",
      "nullable": true
     },
     "cancel_note": {
      "type": "string",
      "maxLength": 200,
      "example": "Customer left before the food came",
      "nullable": true,
      "description": "Optional note from Cancel order (PAN-74), trimmed, at most 200 characters. Null unless the order was cancelled with a note. Visible to every role that can read the order."
     },
     "cancelled_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z",
      "nullable": true,
      "description": "PAN-82. When the order was cancelled, by Cancel order or (PAN-343) by Confirm when every item ends up cancelled. Null while the order is not cancelled, on orders cancelled before PAN-82, and on orders auto-cancelled by Confirm before PAN-343."
     },
     "cancelled_by_name": {
      "type": "string",
      "nullable": true,
      "example": "Sari",
      "description": "PAN-84, PAN-105, PAN-343. The name of the person who cancelled the order, copied at cancel time (no staff id), so it stays after that person is removed or renamed. Code staff of this business use the staff login name; owners and invited Google members use the directory display name, else its email. Another business's member is never stored. Also set (the confirming caller) when Confirm auto-cancels the order (PAN-343). Null when the order is not cancelled, was cancelled before PAN-82, was auto-cancelled by Confirm before PAN-343, or nobody can be named. Visible to every role that can read the order."
     },
     "items": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/OrderItem"
      }
     },
     "subtotal": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "PAN-129. Sum of the non-cancelled lines."
     },
     "charges_total": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "4650.00",
      "description": "PAN-129. Sum of the order's charge amounts."
     },
     "charges": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/OrderCharge"
      },
      "description": "PAN-129. Charges taken at the first confirm (empty before that), in sort_order, removed ones included with amount 0."
     },
     "total": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp. Since PAN-129 subtotal + charges_total; balance and the close payment use it too. Reports keep total_sales as item sales only; charges reach cash_in through payments."
     },
     "paid": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "balance": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "items_total": {
      "type": "integer",
      "example": 4,
      "description": "PAN-87. Non-cancelled lines of the order, so a list card can draw its progress bar without reading the items."
     },
     "items_ready": {
      "type": "integer",
      "example": 2,
      "description": "PAN-87. Non-cancelled lines that are ready or served."
     },
     "items_served": {
      "type": "integer",
      "example": 1,
      "description": "PAN-87. Non-cancelled lines that are served."
     }
    }
   },
   "OrderCancel": {
    "type": "object",
    "properties": {
     "note": {
      "type": "string",
      "nullable": true,
      "example": "Customer left before the food came",
      "description": "Optional. Trimmed; empty or white space only means no note. At most 200 characters after trimming (422 `cancel_note_too_long`)."
     }
    },
    "description": "Optional body of Cancel order (PAN-74). Omit it, or send `{}`, to cancel without a note."
   },
   "ExpenseCategory": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "name": {
      "type": "string",
      "example": "Gas"
     },
     "kind": {
      "type": "string",
      "enum": [
       "cogs",
       "opex"
      ]
     }
    }
   },
   "ExpenseCategoryWrite": {
    "type": "object",
    "properties": {
     "name": {
      "type": "string",
      "example": "Packaging"
     },
     "kind": {
      "type": "string",
      "enum": [
       "cogs",
       "opex"
      ]
     }
    },
    "required": [
     "name",
     "kind"
    ]
   },
   "ExpenseLineWrite": {
    "type": "object",
    "properties": {
     "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Decimal string, up to 3 dp, in unit (or the ingredient stock unit when unit is omitted)."
     },
     "unit": {
      "type": "string",
      "enum": [
       "pcs",
       "g",
       "kg",
       "mg",
       "ml",
       "l"
      ],
      "example": "kg",
      "nullable": true,
      "description": "PAN-95. Optional unit the quantity is entered in, in the ingredient family (g/kg/mg, ml/l, or pcs alone); omitted or null means the stock unit. Another family is 422 unit_family_mismatch; any other value is 422 validation_failed (field ingredient_lines[i].unit, or unit on add-line). The server converts to the stock unit with exact decimal math, rounded half up at 3 dp (a result of 0.000 is 422 validation_failed on quantity). Stock, the stock movement and avg_unit_cost use the converted quantity; line_cost is unchanged, so avg_unit_cost stays per stock unit."
     },
     "line_cost": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     }
    },
    "required": [
     "ingredient_id",
     "quantity",
     "line_cost"
    ]
   },
   "ExpenseLine": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "ingredient_name": {
      "type": "string",
      "example": "Beras",
      "description": "Current name of the ingredient (joined from ingredients, not stored on the line)."
     },
     "unit": {
      "type": "string",
      "example": "kg",
      "description": "Current stock unit of the ingredient (joined from ingredients, not stored on the line), as in `GET /v1/ingredients`. quantity is in this unit."
     },
     "quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Decimal string, 3 dp. PAN-95 - the quantity converted to the ingredient stock unit (unit); this is what was added to stock."
     },
     "line_unit": {
      "type": "string",
      "example": "kg",
      "description": "PAN-95. The unit the line was entered in (the stock unit when none was sent)."
     },
     "line_quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "PAN-95. The quantity as entered, in line_unit, 3 dp."
     },
     "line_cost": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "voided": {
      "type": "boolean",
      "description": "PAN-210. True when this line was voided (present on GET /v1/expenses/{id} with voided lines)."
     },
     "voided_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "PAN-210. When the line was voided."
     },
     "voided_by_name": {
      "type": "string",
      "nullable": true,
      "description": "PAN-210. Who voided or corrected the line, from the latest finance_amendments.actor_name. PAN-322 / PAN-336: the actor's name: the shard staff login name, else the directory account display name, else its email; never the creator, never another business's staff or owner, never a payroll employee. A stored blank name is resolved at read time; when nobody can be named it stays blank."
     },
     "void_reason": {
      "type": "string",
      "nullable": true,
      "description": "PAN-210. Void/correct reason from the latest finance_amendments row for this line."
     },
     "can_edit": {
      "type": "boolean",
      "description": "PAN-218. Present on GET /v1/expenses/{id}. Reuses ComputePurchaseRights (same as DayEntry)."
     },
     "can_void": {
      "type": "boolean",
      "description": "PAN-218 / PAN-335. Present on GET /v1/expenses/{id}. True with stock.void, the creator window, or stock.override; not with finance.amend or stock.correct alone. False when the line is already voided."
     },
     "can_correct": {
      "type": "boolean",
      "description": "PAN-218. Present on GET /v1/expenses/{id}. stock.override holders may correct a voided line."
     },
     "locked_reason": {
      "type": "string",
      "nullable": true,
      "enum": [
       "permission",
       "window",
       "voided",
       "insufficient_stock"
      ],
      "description": "PAN-218. Present on GET /v1/expenses/{id} for each ingredient line (expense-level locked_reason is unchanged).\nHolders of stock.override get null unless the line is voided (then voided, with can_void=false and can_correct=true).\n"
     }
    }
   },
   "ExpenseCreate": {
    "type": "object",
    "properties": {
     "category_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "amount": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "incurred_on": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04"
     },
     "supplier": {
      "type": "string",
      "example": "Pasar Induk"
     },
     "note": {
      "type": "string"
     },
     "confirm_unusual": {
      "type": "boolean",
      "description": "PAN-202. Required true to proceed after 422 unusual_value (Save anyway)."
     },
     "replaces_line_id": {
      "type": "string",
      "format": "uuid",
      "description": "PAN-202. Links a corrected stock-in to the voided original purchase line."
     },
     "ingredient_lines": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/ExpenseLineWrite"
      },
      "description": "Each line adds stock in the same transaction (purchase movement, quantity and moving-average cost updated). Sum of line_cost must be <= amount."
     }
    },
    "required": [
     "category_id",
     "amount",
     "incurred_on"
    ]
   },
   "ExpensePatchRequest": {
    "type": "object",
    "description": "At least one field must change (else 422 `no_changes`). Only plain expenses (no ingredient lines, not payroll) can be edited.",
    "minProperties": 1,
    "properties": {
     "amount": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "125000.00",
      "description": "New amount (PAN-126)."
     },
     "reason": {
      "type": "string",
      "nullable": true,
      "maxLength": 200,
      "example": "Wrong receipt",
      "description": "Optional reason for the change, saved on the amendment. Trimmed; blank is saved as null."
     },
     "category_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
      "description": "Same-merchant expense category."
     },
     "incurred_on": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04",
      "description": "Merchant-local business day."
     },
     "supplier": {
      "type": "string",
      "nullable": true,
      "maxLength": 255,
      "example": "Pasar Induk",
      "description": "null or empty string clears the supplier."
     },
     "note": {
      "type": "string",
      "nullable": true,
      "maxLength": 4000,
      "description": "null or empty string clears the note."
     }
    }
   },
   "ExpenseDeleteRequest": {
    "type": "object",
    "properties": {
     "reason": {
      "type": "string",
      "nullable": true,
      "maxLength": 200,
      "example": "Entered twice",
      "description": "Optional reason, saved on the delete amendment. Trimmed; blank is saved as null."
     }
    }
   },
   "ExpenseAmendment": {
    "type": "object",
    "required": [
     "id",
     "expense_id",
     "action",
     "changes",
     "reason",
     "actor_name",
     "created_at"
    ],
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "expense_id": {
      "type": "string",
      "format": "uuid"
     },
     "action": {
      "type": "string",
      "enum": [
       "edit",
       "delete"
      ]
     },
     "changes": {
      "type": "object",
      "description": "Old and new value per changed field (`category_id`, `amount`, `incurred_on`, `supplier`, `note`). Empty for a delete.",
      "additionalProperties": {
       "type": "object",
       "required": [
        "old",
        "new"
       ],
       "properties": {
        "old": {
         "type": "string",
         "nullable": true
        },
        "new": {
         "type": "string",
         "nullable": true
        }
       }
      },
      "example": {
       "amount": {
        "old": "100000.00",
        "new": "125000.00"
       }
      }
     },
     "reason": {
      "type": "string",
      "nullable": true,
      "maxLength": 200
     },
     "change_list": {
      "type": "array",
      "description": "PAN-221. Presented field changes (`field`, `before`, `after`). Additive; `changes` stays the old map until the app switches.",
      "items": {
       "$ref": "#/components/schemas/AuditChange"
      }
     },
     "actor_name": {
      "type": "string",
      "description": "PAN-352 / PAN-221. Who made the edit or delete, copied at write time (not linked to staff): this business's staff login name, else the directory account display name, else its email; never another business's member, never a payroll employee, never a synthetic @staff.invalid address. A blank or literal Unknown name is filled from actor_id when that person can still be named. When nobody can be named the value is Nama tidak tersedia (never the literal Unknown).",
      "example": "Benny"
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     }
    }
   },
   "Expense": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "category_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "amount": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Live total (decimal string, 2 dp). Voided ingredient lines are excluded."
     },
     "original_amount": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Sum of all ingredient lines including voided ones, at their current/corrected line_cost (2 dp). For non-stock expenses (no lines) equals amount."
     },
     "voided": {
      "type": "boolean",
      "example": false,
      "description": "True when the expense has ingredient lines and every line is voided."
     },
     "incurred_on": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04"
     },
     "supplier": {
      "type": "string",
      "nullable": true
     },
     "note": {
      "type": "string",
      "nullable": true
     },
     "created_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     },
     "created_by_name": {
      "type": "string",
      "nullable": true,
      "example": "Benny",
      "description": "Name of who created the expense, copied at create time (not linked to staff). PAN-343 code staff of this business use the staff login name; owners and invited Google members use the directory display name, else its email. null for expenses created before PAN-126, for payroll expenses, and when nobody can be named."
     },
     "voided_by_name": {
      "type": "string",
      "nullable": true,
      "example": "Rita",
      "description": "PAN-336 (additive). Who made the latest void or correction of any of this expense's purchase lines (voided lines included): the actor's name: the shard staff login name, else the directory account display name, else its email; never the creator, never another business's staff or owner, never a payroll employee. Not created_by_name. null when no line was voided or corrected, or when nobody can be named."
     },
     "ingredient_lines": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/ExpenseLine"
      }
     },
     "locked_reason": {
      "type": "string",
      "nullable": true,
      "enum": [
       "stock",
       "payroll",
       null
      ],
      "example": null,
      "description": "Why PATCH and DELETE refuse this expense, from the same rule as their 409 guards. `stock` means it has ingredient lines (409 `expense_has_ingredient_lines`); `payroll` means a payroll run is linked (409 `expense_is_payroll`); `null` means it is editable. When both apply it is `stock`, the guard that answers first."
     }
    }
   },
   "AuditLineWrite": {
    "type": "object",
    "properties": {
     "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "counted_quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Decimal string, up to 3 dp."
     },
     "note": {
      "type": "string"
     }
    },
    "required": [
     "ingredient_id",
     "counted_quantity"
    ]
   },
   "AuditCreate": {
    "type": "object",
    "properties": {
     "lines": {
      "type": "array",
      "minItems": 1,
      "items": {
       "$ref": "#/components/schemas/AuditLineWrite"
      }
     }
    },
    "required": [
     "lines"
    ],
    "description": "End-of-day count. expected_quantity is computed server-side from the ledger. audited_by is the actor's email (see StockAudit.audited_by)."
   },
   "StockAudit": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "expected_quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Decimal string, up to 3 dp."
     },
     "counted_quantity": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Decimal string, up to 3 dp."
     },
     "variance": {
      "type": "string",
      "example": "-6.000"
     },
     "audited_by": {
      "type": "string",
      "example": "owner@example.com",
      "description": "The actor's email, or their staff name or username when there is no email. Owners and invited Google members use the directory account email. Code staff of this business use staff_logins.email, or if that is empty their staff name, or if that is empty their employee ID (the login username). The synthetic @staff.invalid account address is never stored.\n"
     },
     "audited_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     },
     "note": {
      "type": "string",
      "nullable": true
     }
    }
   },
   "EmployeeWrite": {
    "type": "object",
    "properties": {
     "full_name": {
      "type": "string",
      "example": "Budi"
     },
     "role": {
      "type": "string",
      "example": "Barista"
     },
     "pay_type": {
      "type": "string",
      "enum": [
       "hourly",
       "monthly"
      ]
     },
     "hourly_rate": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp.",
      "nullable": true
     },
     "monthly_salary": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp.",
      "nullable": true
     },
     "is_active": {
      "type": "boolean"
     },
     "hired_on": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04",
      "nullable": true,
      "description": "First day of the employee's active range (inclusive). Null is no start bound."
     },
     "left_on": {
      "type": "string",
      "format": "date",
      "example": "2026-10-31",
      "nullable": true,
      "description": "Last day worked (inclusive). Must be on or after hired_on (422). A leaver can be set inactive and still gets a prorated line for the runs their range touches. On PATCH, omitted keeps it, null clears it."
     }
    },
    "required": [
     "full_name",
     "pay_type"
    ],
    "description": "hourly requires hourly_rate; monthly requires monthly_salary."
   },
   "Employee": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "full_name": {
      "type": "string",
      "example": "Budi"
     },
     "role": {
      "type": "string",
      "example": "Barista",
      "nullable": true
     },
     "pay_type": {
      "type": "string",
      "enum": [
       "hourly",
       "monthly"
      ]
     },
     "hourly_rate": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp.",
      "nullable": true
     },
     "monthly_salary": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp.",
      "nullable": true
     },
     "is_active": {
      "type": "boolean"
     },
     "hired_on": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04",
      "nullable": true
     },
     "left_on": {
      "type": "string",
      "format": "date",
      "example": null,
      "nullable": true,
      "description": "Last day worked (inclusive), null when not set."
     }
    }
   },
   "ShiftCreate": {
    "type": "object",
    "properties": {
     "started_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     },
     "ended_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z",
      "nullable": true
     }
    },
    "required": [
     "started_at"
    ]
   },
   "ShiftUpdate": {
    "type": "object",
    "properties": {
     "started_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     },
     "ended_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     }
    },
    "minProperties": 1,
    "description": "At least one of started_at and ended_at. Omitted fields keep their value; ended_at cannot be null."
   },
   "Shift": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "employee_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "started_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     },
     "ended_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z",
      "nullable": true
     },
     "locked_reason": {
      "type": "string",
      "nullable": true,
      "enum": [
       "payroll",
       null
      ],
      "example": null,
      "description": "`payroll` when the shift is in a paid payroll run (a closed shift overlapping the period of a paid run): PATCH and DELETE return 409 `shift_locked`. `null` means it is editable. Open shifts are never locked, but cannot be ended into a paid period."
     }
    },
    "required": [
     "id",
     "employee_id",
     "started_at",
     "ended_at",
     "locked_reason"
    ]
   },
   "PayrollPreview": {
    "type": "object",
    "properties": {
     "period_start": {
      "type": "string",
      "format": "date"
     },
     "period_end": {
      "type": "string",
      "format": "date"
     },
     "frequency": {
      "type": "string",
      "enum": [
       "daily",
       "weekly",
       "biweekly",
       "monthly"
      ]
     },
     "timezone": {
      "type": "string",
      "description": "The merchant timezone a run created now would store."
     },
     "salary_proration": {
      "type": "string",
      "enum": [
       "working_days",
       "hourly"
      ]
     },
     "open_shifts": {
      "type": "boolean",
      "description": "A shift that started before the end of the period is still open, so pay would be refused."
     },
     "open_shifts_count": {
      "type": "integer",
      "minimum": 0,
      "description": "PAN-83. How many shifts of the business that started before the end of the period are still open (the shifts that make pay refuse with open_shifts_in_period). open_shifts is true exactly when this is above 0."
     },
     "entries": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PayrollPreviewEntry"
      }
     },
     "total_gross_pay": {
      "type": "string",
      "example": "8100000.00"
     },
     "total_net_pay": {
      "type": "string",
      "example": "8100000.00"
     }
    }
   },
   "PayrollPreviewEntry": {
    "type": "object",
    "properties": {
     "employee_id": {
      "type": "string",
      "format": "uuid"
     },
     "employee_name": {
      "type": "string"
     },
     "pay_type": {
      "type": "string",
      "enum": [
       "hourly",
       "monthly"
      ]
     },
     "hours_worked": {
      "type": "string",
      "nullable": true,
      "example": "8.50"
     },
     "days_worked": {
      "type": "integer",
      "nullable": true
     },
     "gross_pay": {
      "type": "string",
      "example": "2700000.00"
     },
     "deductions": {
      "type": "string",
      "example": "0.00"
     },
     "net_pay": {
      "type": "string",
      "example": "2700000.00"
     }
    }
   },
   "PayrollRunCreate": {
    "type": "object",
    "properties": {
     "period_start": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04"
     },
     "period_end": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04"
     },
     "frequency": {
      "type": "string",
      "enum": [
       "daily",
       "weekly",
       "biweekly",
       "monthly"
      ],
      "description": "Label only; defaults to the merchant's payroll_frequency. The period is not checked against it."
     }
    },
    "required": [
     "period_start",
     "period_end"
    ],
    "description": "Creates a draft run (hourly staff: hours from shifts x rate; monthly staff: prorated salary, see the operation)."
   },
   "PayrollEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "employee_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "hours_worked": {
      "type": "string",
      "example": "10.00",
      "nullable": true,
      "description": "Closed-shift hours in the period. Set for hourly staff, and for monthly staff when salary_proration is hourly; null otherwise."
     },
     "days_worked": {
      "type": "integer",
      "example": 13,
      "nullable": true,
      "description": "Active working days counted for a monthly employee when salary_proration is working_days; null otherwise."
     },
     "gross_pay": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "deductions": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "net_pay": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     }
    }
   },
   "PayrollRun": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "period_start": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04"
     },
     "period_end": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04"
     },
     "status": {
      "type": "string",
      "enum": [
       "draft",
       "paid"
      ]
     },
     "frequency": {
      "type": "string",
      "enum": [
       "daily",
       "weekly",
       "biweekly",
       "monthly"
      ],
      "description": "Label set when the run was created."
     },
     "timezone": {
      "type": "string",
      "example": "Asia/Jakarta",
      "description": "Merchant timezone when the run was created; the period edges use it."
     },
     "expense_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34",
      "nullable": true
     },
     "paid_on": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04",
      "nullable": true
     },
     "entries": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/PayrollEntry"
      }
     }
    }
   },
   "PayrollPay": {
    "type": "object",
    "properties": {
     "paid_on": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04"
     }
    },
    "description": "Optional; defaults to today in the merchant timezone."
   },
   "PlanLimits": {
    "type": "object",
    "properties": {
     "max_merchants": {
      "type": "integer",
      "description": "Businesses one account may own. The same number the server enforces (tier_limits.max_merchants), plus add-ons in limits.effective. Always a number today; no tier is unlimited."
     },
     "max_menu_items": {
      "type": "integer"
     },
     "max_employee_accounts": {
      "type": "integer",
      "description": "Per business."
     },
     "storage_bytes": {
      "type": "integer",
      "format": "int64"
     }
    }
   },
   "Price": {
    "type": "object",
    "nullable": true,
    "description": "A placeholder amount until real prices are set. null means no price.",
    "properties": {
     "amount": {
      "type": "string",
      "example": "249000"
     },
     "currency": {
      "type": "string",
      "example": "IDR"
     },
     "period": {
      "type": "string",
      "enum": [
       "none",
       "month",
       "one_time"
      ]
     }
    }
   },
   "PlanSelection": {
    "type": "object",
    "nullable": true,
    "description": "The saved plan choice, or null. Saving it charges nothing and raises no limit.",
    "properties": {
     "tier": {
      "type": "string",
      "enum": [
       "MONTHLY",
       "LIFETIME"
      ]
     },
     "add_ons": {
      "type": "array",
      "description": "In catalog order. Empty when none.",
      "items": {
       "type": "object",
       "properties": {
        "key": {
         "type": "string",
         "enum": [
          "extra_businesses",
          "extra_employee_accounts",
          "extra_items",
          "extra_image_storage"
         ]
        },
        "quantity": {
         "type": "integer",
         "minimum": 1
        }
       }
      }
     },
     "selected_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the tier or add-ons last changed. Repeating the same choice keeps it."
     },
     "remind_after": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "Set by remind_later (now + 7 days). Null otherwise."
     }
    }
   },
   "MerchantLimits": {
    "type": "object",
    "properties": {
     "effective": {
      "$ref": "#/components/schemas/PlanLimits"
     },
     "if_active": {
      "nullable": true,
      "description": "What the saved choice would give if it were active (base plan plus add-ons). Non-null only while\nplan_state is plan_selected_pending_payment. Informational, so the app never computes limit math itself.\n",
      "allOf": [
       {
        "$ref": "#/components/schemas/PlanLimits"
       }
      ]
     }
    }
   },
   "PlanCatalog": {
    "type": "object",
    "properties": {
     "plans": {
      "type": "array",
      "description": "In order FREE, MONTHLY, LIFETIME.",
      "items": {
       "type": "object",
       "properties": {
        "tier": {
         "type": "string",
         "enum": [
          "FREE",
          "MONTHLY",
          "LIFETIME"
         ]
        },
        "name": {
         "type": "string"
        },
        "price": {
         "$ref": "#/components/schemas/Price"
        },
        "purchasable": {
         "type": "boolean",
         "description": "Always false until payments exist."
        },
        "placeholder": {
         "type": "boolean",
         "description": "true while the price is a placeholder."
        },
        "default": {
         "type": "boolean",
         "description": "The plan to preselect (Monthly)."
        },
        "add_ons_allowed": {
         "type": "boolean"
        },
        "limits": {
         "$ref": "#/components/schemas/PlanLimits"
        }
       }
      }
     },
     "add_ons": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "key": {
         "type": "string",
         "enum": [
          "extra_businesses",
          "extra_employee_accounts",
          "extra_items",
          "extra_image_storage"
         ]
        },
        "label": {
         "type": "string"
        },
        "unit": {
         "type": "string",
         "example": "pack_5_gib"
        },
        "price": {
         "$ref": "#/components/schemas/Price"
        },
        "purchasable": {
         "type": "boolean"
        },
        "placeholder": {
         "type": "boolean"
        },
        "max_quantity": {
         "type": "integer"
        },
        "adds": {
         "type": "object",
         "description": "Limit key to the amount one unit adds (max_merchants, max_employee_accounts, max_menu_items, storage_bytes).",
         "additionalProperties": {
          "type": "integer",
          "format": "int64"
         }
        }
       }
      }
     }
    }
   },
   "PlanSelectionRequest": {
    "type": "object",
    "properties": {
     "tier": {
      "type": "string",
      "enum": [
       "MONTHLY",
       "LIFETIME"
      ],
      "description": "Required unless the body is only remind_later. FREE or unknown is 422 plan_not_available."
     },
     "add_ons": {
      "type": "array",
      "items": {
       "type": "object",
       "additionalProperties": false,
       "required": [
        "key",
        "quantity"
       ],
       "properties": {
        "key": {
         "type": "string"
        },
        "quantity": {
         "type": "integer",
         "minimum": 1
        }
       }
      }
     },
     "remind_later": {
      "type": "boolean"
     }
    }
   },
   "PlanSelectionResult": {
    "type": "object",
    "properties": {
     "plan_state": {
      "type": "string",
      "enum": [
       "plan_selected_pending_payment"
      ]
     },
     "plan_selection": {
      "$ref": "#/components/schemas/PlanSelection"
     },
     "charged": {
      "type": "boolean",
      "description": "Always false."
     },
     "effective_tier": {
      "type": "string",
      "description": "The merchant's real tier (FREE). A saved choice never changes it."
     },
     "limits": {
      "$ref": "#/components/schemas/MerchantLimits"
     }
    }
   },
   "PlanSelectionCleared": {
    "type": "object",
    "properties": {
     "plan_state": {
      "type": "string",
      "enum": [
       "free",
       "active_monthly",
       "active_lifetime",
       "payment_failed"
      ]
     },
     "plan_selection": {
      "nullable": true
     }
    }
   },
   "Onboarding": {
    "type": "object",
    "required": [
     "flow",
     "status",
     "current_step",
     "version",
     "answers",
     "applied_at",
     "categories_seeded_at",
     "completed_at",
     "plan_state",
     "plan_selection"
    ],
    "properties": {
     "flow": {
      "type": "string",
      "enum": [
       "full",
       "second_business"
      ],
      "description": "`second_business` for a merchant added with POST /v1/merchants; its `done` needs only `applied_at`."
     },
     "status": {
      "type": "string",
      "enum": [
       "not_started",
       "in_progress",
       "completed"
      ]
     },
     "current_step": {
      "type": "string",
      "enum": [
       "business",
       "businesses",
       "team",
       "stock",
       "payroll",
       "summary",
       "plan",
       "done"
      ]
     },
     "version": {
      "type": "integer",
      "minimum": 1
     },
     "answers": {
      "$ref": "#/components/schemas/OnboardingAnswers"
     },
     "applied_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true
     },
     "categories_seeded_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true
     },
     "completed_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true
     },
     "plan_state": {
      "type": "string",
      "enum": [
       "free",
       "plan_selected_pending_payment",
       "active_monthly",
       "active_lifetime",
       "payment_failed"
      ]
     },
     "plan_selection": {
      "$ref": "#/components/schemas/PlanSelection"
     }
    }
   },
   "OnboardingAnswers": {
    "type": "object",
    "additionalProperties": false,
    "description": "Only these keys are accepted; anything else is 422.",
    "properties": {
     "currency": {
      "type": "string",
      "enum": [
       "IDR",
       "USD",
       "SGD",
       "MYR",
       "EUR"
      ],
      "description": "PAN-90. Applied to the merchant by `apply`. Allowed while onboarding is not completed and the merchant has no orders; otherwise 422 `currency_locked`. Unknown code is 422 `validation_failed` (`answers.currency`)."
     },
     "business_name": {
      "type": "string",
      "maxLength": 255
     },
     "business_type": {
      "type": "string",
      "enum": [
       "food_drink",
       "retail",
       "services",
       "mix"
      ]
     },
     "timezone": {
      "type": "string",
      "example": "Asia/Jakarta"
     },
     "business_count": {
      "type": "string",
      "enum": [
       "one",
       "two",
       "three_to_five",
       "more_than_five",
       "two_to_five"
      ],
      "description": "two_to_five is the old value, still accepted and stored as sent. New clients send one, two, three_to_five or more_than_five."
     },
     "team_size": {
      "type": "string",
      "enum": [
       "solo",
       "small",
       "large"
      ]
     },
     "item_count": {
      "type": "string",
      "enum": [
       "under_50",
       "50_to_200",
       "200_to_1000",
       "over_1000",
       "over_200"
      ],
      "description": "over_200 is the old value, still accepted and stored as sent. New clients send under_50, 50_to_200, 200_to_1000 or over_1000."
     },
     "track_stock": {
      "type": "boolean"
     },
     "use_recipes": {
      "type": "boolean"
     },
     "payroll_enabled": {
      "type": "boolean"
     },
     "payroll_frequency": {
      "type": "string",
      "enum": [
       "daily",
       "weekly",
       "biweekly",
       "monthly"
      ]
     },
     "salary_proration": {
      "type": "string",
      "enum": [
       "working_days",
       "hourly"
      ]
     },
     "selected_tier": {
      "type": "string",
      "enum": [
       "FREE",
       "MONTHLY",
       "LIFETIME"
      ]
     },
     "selected_add_ons": {
      "type": "array",
      "description": "Add-on catalog keys (extra_businesses, extra_employee_accounts, extra_items, extra_image_storage), at most once each, quantity 1 to the catalog maximum. Not checked against the tier. Selecting enforces and charges nothing.",
      "items": {
       "type": "object",
       "additionalProperties": false,
       "required": [
        "key",
        "quantity"
       ],
       "properties": {
        "key": {
         "type": "string"
        },
        "quantity": {
         "type": "integer",
         "minimum": 1
        }
       }
      }
     }
    }
   },
   "OnboardingUpdate": {
    "type": "object",
    "required": [
     "version"
    ],
    "properties": {
     "version": {
      "type": "integer",
      "minimum": 1
     },
     "current_step": {
      "type": "string",
      "enum": [
       "business",
       "businesses",
       "team",
       "stock",
       "payroll",
       "summary",
       "plan",
       "done"
      ]
     },
     "answers": {
      "$ref": "#/components/schemas/OnboardingAnswers"
     }
    }
   },
   "OnboardingApplyResult": {
    "type": "object",
    "required": [
     "applied_at",
     "categories_created"
    ],
    "properties": {
     "applied_at": {
      "type": "string",
      "format": "date-time"
     },
     "categories_created": {
      "type": "integer",
      "minimum": 0
     }
    }
   },
   "PayrollSettings": {
    "type": "object",
    "properties": {
     "salary_proration": {
      "type": "string",
      "enum": [
       "working_days",
       "hourly"
      ],
      "description": "How monthly salaries are prorated in a run. Default working_days."
     },
     "work_days": {
      "type": "array",
      "items": {
       "type": "integer",
       "minimum": 1,
       "maximum": 7
      },
      "example": [
       1,
       2,
       3,
       4,
       5,
       6
      ],
      "description": "ISO weekdays that are working days (1 = Monday ... 7 = Sunday), sorted. Default Mon-Sat."
     },
     "standard_hours_per_day": {
      "type": "string",
      "example": "8.00",
      "description": "Divisor for hourly proration (salary / (working days in the month x this)), capped per month portion at the working_days amount for the days covered. Default 8."
     },
     "payroll_frequency": {
      "type": "string",
      "enum": [
       "daily",
       "weekly",
       "biweekly",
       "monthly"
      ],
      "description": "Default label for new runs and the length of next_period. Default monthly."
     },
     "next_period": {
      "type": "object",
      "description": "Suggested period for the next run. Starts the day after the latest run (or, with no run, on the 1st of this month / the Monday of this week / today, merchant time). monthly ends on the last day of that calendar month; weekly is 7 days, biweekly 14, daily 1. A suggestion only.",
      "properties": {
       "period_start": {
        "type": "string",
        "format": "date",
        "example": "2026-10-01"
       },
       "period_end": {
        "type": "string",
        "format": "date",
        "example": "2026-10-31"
       }
      },
      "required": [
       "period_start",
       "period_end"
      ]
     }
    },
    "required": [
     "salary_proration",
     "work_days",
     "standard_hours_per_day",
     "payroll_frequency",
     "next_period"
    ]
   },
   "PayrollSettingsUpdate": {
    "type": "object",
    "minProperties": 1,
    "properties": {
     "salary_proration": {
      "type": "string",
      "enum": [
       "working_days",
       "hourly"
      ]
     },
     "work_days": {
      "type": "array",
      "minItems": 1,
      "maxItems": 7,
      "uniqueItems": true,
      "items": {
       "type": "integer",
       "minimum": 1,
       "maximum": 7
      }
     },
     "standard_hours_per_day": {
      "type": "string",
      "pattern": "^\\d{1,2}(\\.\\d{1,2})?$",
      "example": "8",
      "description": "Above 0 and at most 24, up to 2 decimal places."
     },
     "payroll_frequency": {
      "type": "string",
      "enum": [
       "daily",
       "weekly",
       "biweekly",
       "monthly"
      ]
     }
    }
   },
   "ExpenseCategoryTotal": {
    "type": "object",
    "properties": {
     "category_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "name": {
      "type": "string",
      "example": "Materials"
     },
     "kind": {
      "type": "string",
      "enum": [
       "cogs",
       "opex"
      ]
     },
     "total": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     }
    },
    "required": [
     "category_id",
     "name",
     "kind",
     "total"
    ]
   },
   "LowStockIngredient": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "ingredient_name": {
      "type": "string",
      "example": "Coffee beans"
     },
     "unit": {
      "type": "string",
      "example": "g"
     },
     "stock_quantity": {
      "type": "string",
      "example": "4.000"
     },
     "min_quantity": {
      "type": "string",
      "example": "5.000"
     }
    },
    "required": [
     "id",
     "ingredient_name",
     "unit",
     "stock_quantity",
     "min_quantity"
    ],
    "description": "Current stock is less than or equal to min_quantity. Not filtered by the report dates."
   },
   "CashflowDay": {
    "type": "object",
    "properties": {
     "day": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04"
     },
     "total_sales": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "refunds": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "The full amount of completed refunds (charges and tax included), dated by the refund paid_at. Cash, not the Net base; see sales_refunds. Decimal string, rounded to 2 dp."
     },
     "net_sales": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "PAN-391 Net sales (Penjualan bersih) = gross_sales - sales_refunds: item sales after their refund share plus revenue charges after theirs. Tax, collected_for_others and Unclassified charges are never in it. Margin base. Before PAN-391 this was total_sales - refunds. Decimal string, rounded to 2 dp."
     },
     "gross_sales": {
      "type": "string",
      "example": "31000.00",
      "description": "PAN-391 Gross sales (Penjualan kotor) = total_sales + revenue charges: snapshot amounts of charges whose order took kind revenue, on closed orders dated by COALESCE(closed_at, ordered_at), like total_sales. For orders paid on the day they close this is paid_sales minus tax, collected_for_others and Unclassified charges. 2 dp."
     },
     "sales_refunds": {
      "type": "string",
      "example": "1050.00",
      "description": "PAN-391 the part of refunds that was sales (your share of refunds): refunds minus the refund_share of tax, collected_for_others and Unclassified charges (order snapshot kind), so the menu-price part plus the revenue-charge part. Dated by the refund paid_at. Summed unrounded and rounded once. 2 dp."
     },
     "cost_of_sales": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Ingredient cost of sold items (sale stock movements at unit_cost). Excludes waste and expenses (PAN-130). Decimal string, rounded to 2 dp."
     },
     "gross_profit": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "net_sales minus cost_of_sales. Expenses never change it (PAN-143). Decimal string, rounded to 2 dp."
     },
     "operating_expenses": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "PAN-143. Every expense in the period (any category kind, manual or payroll) minus the part covered by ingredient purchase lines, which is stock and reaches profit through sale and waste movements. Lowers net_profit only, never gross_profit. Decimal string, rounded to 2 dp."
     },
     "waste_cost": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "15000.00",
      "description": "PAN-130. Cost of waste stock movements (write-offs) at unit_cost. Not part of cost_of_sales; lowers net_profit. Needs costs.view. Decimal string, rounded to 2 dp."
     },
     "net_profit": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "gross_profit - operating_expenses - waste_cost, on the PAN-391 Net sales (revenue charges in, pass-through and Unclassified charges out). Needs costs.view. Decimal string, rounded to 2 dp."
     },
     "cash_in": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "cash_out": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,2})?$",
      "example": "30000.00",
      "description": "Decimal string, rounded to 2 dp."
     },
     "net_cash": {
      "type": "string",
      "example": "0.00",
      "description": "cash_in minus cash_out for this bucket. Decimal string rounded to 2 dp. May be negative."
     },
     "paid_sales": {
      "type": "string",
      "example": "1150000.00",
      "description": "PAN-391. Paid by customers (Dibayar pelanggan): completed payments on closed orders, dated by paid_at in the merchant timezone, the same basis as the sales report paid_sales. 2 dp."
     },
     "charges": {
      "type": "array",
      "description": "PAN-391. One entry per charge used in this bucket, ordered by charge_id. Names, kinds and notes are in the sales report charges list (same charge_id). Empty when no charge was used.",
      "items": {
       "$ref": "#/components/schemas/PeriodCharge"
      }
     }
    },
    "required": [
     "paid_sales",
     "charges",
     "gross_sales",
     "sales_refunds"
    ],
    "description": "One bucket of the daily_financials summary (same formulas as v_daily_cashflow) put on the PAN-391 Net definition (gross_sales = total_sales + revenue charges; net_sales = gross_sales - sales_refunds; daily_financials itself keeps menu-price sales and the full refund), plus net_cash (cash_in minus cash_out). cash_in is net of refunds; cash_out includes all expenses. gross_profit is net_sales minus cost_of_sales, the ingredient cost of sold items (sale movements only, PAN-130). waste_cost is write-offs (waste movements). operating_expenses is every expense minus ingredient purchase line costs (PAN-143); expenses never change gross_profit. net_profit = gross_profit - operating_expenses - waste_cost."
   },
   "PeriodCharge": {
    "type": "object",
    "properties": {
     "charge_id": {
      "type": "string",
      "format": "uuid"
     },
     "amount": {
      "type": "string",
      "example": "50000.00",
      "description": "Snapshot amounts of this charge on closed orders dated by COALESCE(closed_at, ordered_at) in this bucket, like charges_total. 2 dp."
     },
     "refund_share": {
      "type": "string",
      "example": "2500.00",
      "description": "The part of completed refunds (dated by the refund paid_at) that paid back this charge: refund x charge amount / (item sales + charges) of its order. Proportional until per-line refunds exist. 2 dp."
     }
    },
    "required": [
     "charge_id",
     "amount",
     "refund_share"
    ]
   },
   "CashflowReport": {
    "type": "object",
    "properties": {
     "currency": {
      "type": "string",
      "example": "IDR",
      "description": "PAN-90. ISO 4217 code of the business currency. Amounts stay 2 dp decimal strings."
     },
     "from": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04"
     },
     "to": {
      "type": "string",
      "format": "date",
      "example": "2026-10-04"
     },
     "group_by": {
      "type": "string",
      "enum": [
       "day",
       "week",
       "month"
      ]
     },
     "cash_in": {
      "type": "string",
      "example": "30000.00",
      "description": "Period total. Completed payments minus completed refunds. Same value as totals.cash_in."
     },
     "cash_out": {
      "type": "string",
      "example": "10000.00",
      "description": "Period total of every expense. Same value as totals.cash_out."
     },
     "net_cash": {
      "type": "string",
      "example": "20000.00",
      "description": "cash_in minus cash_out for the period. Decimal string rounded to 2 dp. May be negative. Same value as totals.net_cash."
     },
     "gross_profit": {
      "type": "string",
      "example": "15000.00",
      "description": "net_sales minus ingredient cost of goods sold (sale and waste stock movements at unit_cost) for the period. May be negative. Same value as totals.gross_profit."
     },
     "expenses_by_category": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/ExpenseCategoryTotal"
      },
      "description": "Expense totals in the period, one row per category that had spending."
     },
     "has_low_stock": {
      "type": "boolean",
      "description": "True when at least one ingredient is at or below its min_quantity."
     },
     "low_stock": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/LowStockIngredient"
      }
     },
     "rows": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/CashflowDay"
      }
     },
     "totals": {
      "$ref": "#/components/schemas/CashflowDay"
     },
     "previous": {
      "$ref": "#/components/schemas/CashflowPeriod"
     }
    }
   },
   "SalesReport": {
    "type": "object",
    "properties": {
     "currency": {
      "type": "string",
      "example": "IDR",
      "description": "PAN-90. ISO 4217 code of the business currency. Amounts stay 2 dp decimal strings."
     },
     "from": {
      "type": "string",
      "format": "date",
      "example": "2026-10-01",
      "description": "The from query parameter as sent (trimmed, YYYY-MM-DD). An empty string, not a date, when from was omitted (no start bound)."
     },
     "to": {
      "type": "string",
      "format": "date",
      "example": "2026-10-10",
      "description": "The to query parameter as sent (trimmed, YYYY-MM-DD). An empty string, not a date, when to was omitted (no end bound)."
     },
     "type": {
      "type": "string",
      "enum": [
       "most_items_sold",
       "most_sales",
       "most_refunds",
       "most_net_sales",
       "most_cost_of_sales",
       "most_gross_profit",
       "most_item_sales_after_refunds",
       "most_gross_profit_after_refunds"
      ],
      "description": "The type query parameter. It is the order of items."
     },
     "items": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/SalesItem"
      }
     },
     "next_cursor": {
      "type": "string",
      "nullable": true,
      "description": "Pass as the cursor query parameter to read the next page. Null on the last page."
     },
     "paid_sales": {
      "type": "string",
      "example": "250000.00",
      "description": "PAN-142. Paid sales total: the sum of completed payment rows (kind payment) on closed orders whose paid_at falls in from..to in the merchant timezone. Cancelled orders are excluded. Equals the sum of every payments_by_method amount, the other entry included."
     },
     "payments_by_method": {
      "type": "array",
      "description": "PAN-142. Always the four entries cash, qris, card, transfer in that order (unused ones have count 0 and amount 0.00), then a fifth entry other only when payment rows with no known method exist in the range (the app labels it Method not recorded). Every entry adds up to paid_sales. amount is the amount applied to the bill, not cash_received. Split payments count once per payment row.",
      "items": {
       "type": "object",
       "properties": {
        "method": {
         "type": "string",
         "enum": [
          "cash",
          "qris",
          "card",
          "transfer",
          "other"
         ]
        },
        "count": {
         "type": "integer",
         "minimum": 0,
         "example": 2,
         "description": "Number of payment rows."
        },
        "amount": {
         "type": "string",
         "example": "70000.00"
        }
       },
       "required": [
        "method",
        "count",
        "amount"
       ]
      }
     },
     "other_payments": {
      "type": "object",
      "description": "PAN-142. Kept for older clients: the same count and amount as the payments_by_method other entry, or zero when it is absent.",
      "properties": {
       "count": {
        "type": "integer",
        "minimum": 0
       },
       "amount": {
        "type": "string",
        "example": "0.00"
       }
      }
     },
     "charges_total": {
      "type": "string",
      "example": "42780.00",
      "description": "PAN-142. Bill charges (PAN-129, service and tax) on closed orders dated by COALESCE(closed_at, ordered_at) in from..to in the merchant timezone, the same dating as total_sales. For orders paid on the day they close, total_sales + charges_total = paid_sales."
     },
     "item_sales": {
      "type": "string",
      "example": "1000000.00",
      "description": "PAN-391. Item sales (Penjualan menu): quantity x unit price of non-cancelled lines on closed orders in from..to (dated like the items), before refunds, with no charges added and never tax-adjusted. The sum of every item's line revenue, not only this page."
     },
     "charges": {
      "type": "array",
      "description": "PAN-391. One entry per charge used on closed orders in from..to (same dating and snapshot amounts as charges_total, which stays their sum), grouped by charge_id so a rename never splits a column. Ordered like GET /v1/charges. Each tax, collected_for_others and Unclassified charge needs its own column; only revenue charges may be folded into Other charges.",
      "items": {
       "$ref": "#/components/schemas/ReportCharge"
      }
     },
     "totals": {
      "$ref": "#/components/schemas/SalesTotals"
     }
    },
    "required": [
     "from",
     "to",
     "type",
     "items",
     "paid_sales",
     "payments_by_method",
     "other_payments",
     "charges_total",
     "item_sales",
     "charges",
     "totals"
    ]
   },
   "SalesTotals": {
    "type": "object",
    "description": "PAN-391. Every item over from..to, not only this page, for the per-item Total row. Each value is summed unrounded and rounded once, so it can differ from the sum of the rounded item rows by a cent.",
    "properties": {
     "sold_count": {
      "type": "string",
      "example": "355",
      "description": "Units sold on closed bills (cancelled lines left out, refunds never lower it)."
     },
     "item_sales": {
      "type": "string",
      "example": "100000000.00",
      "description": "Same as the top-level item_sales."
     },
     "item_sales_after_refunds": {
      "type": "string",
      "example": "98500000.00",
      "description": "Item sales minus the menu-price part of refunds (0070: refund x item sales / paid by customers), each refund dated by the day it was paid (0074). The sum of the items' item_sales_after_refunds. Label it \"Item sales after refunds\" / \"Penjualan menu setelah refund\", never Net sales."
     },
     "cost_of_sales": {
      "type": "string",
      "example": "40000000.00",
      "description": "Ingredient cost of the lines sold. Omitted without costs.view."
     },
     "revenue_charges": {
      "type": "string",
      "example": "3000000.00",
      "description": "PAN-391 (0075). The items' revenue charges after their refund share (sum of the items' revenue_charges)."
     },
     "net_sales": {
      "type": "string",
      "example": "101500000.00",
      "description": "PAN-391 (0075). item_sales_after_refunds + revenue_charges, the sum of the items' net_sales. Equals cashflow totals.net_sales for the same period up to rounding (cashflow rounds sales_refunds once per bucket)."
     },
     "operating_expenses": {
      "type": "string",
      "example": "12000000.00",
      "description": "PAN-391. The period's operating expenses (every expense minus the part covered by ingredient purchase lines, PAN-143), read from daily_financials over the same business days, so it equals cashflow totals.operating_expenses. Not an item cost. Omitted without costs.view."
     },
     "waste_cost": {
      "type": "string",
      "example": "1500000.00",
      "description": "PAN-391. The period's waste write-offs at their unit_cost, read from daily_financials, equal to cashflow totals.waste_cost. Not an item cost (waste has no menu item). With cost_of_sales and operating_expenses it gives the profit chain net_sales - cost_of_sales - operating_expenses - waste_cost for the profit view. Omitted without costs.view."
     }
    },
    "required": [
     "sold_count",
     "item_sales",
     "item_sales_after_refunds",
     "revenue_charges",
     "net_sales"
    ]
   },
   "ReportCharge": {
    "type": "object",
    "description": "PAN-391. One charge column of a sales report.",
    "properties": {
     "charge_id": {
      "type": "string",
      "format": "uuid"
     },
     "name": {
      "type": "string",
      "description": "The charge's current name (its last name when deleted)."
     },
     "kind": {
      "type": "string",
      "nullable": true,
      "enum": [
       "revenue",
       "tax",
       "collected_for_others",
       null
      ],
      "description": "The charge's current kind, for the column heading. Null = Unclassified."
     },
     "deleted": {
      "type": "boolean",
      "description": "Soft-deleted. The app labels the column \"{name} (deleted)\" / \"{name} (dihapus)\"."
     },
     "note": {
      "type": "string",
      "nullable": true,
      "description": "The owner's live note, shown under Panly's line for the kind in the tooltip."
     },
     "total": {
      "type": "string",
      "example": "15000.00"
     },
     "by_kind": {
      "type": "array",
      "description": "total split by the kind each order took (orders keep their kind, so a later kind change never moves past amounts). Kinds revenue, tax, collected_for_others, then unclassified; only kinds with amounts are listed. Unclassified amounts stay out of Gross and Net sales.",
      "items": {
       "type": "object",
       "properties": {
        "kind": {
         "type": "string",
         "enum": [
          "revenue",
          "tax",
          "collected_for_others",
          "unclassified"
         ]
        },
        "amount": {
         "type": "string",
         "example": "10000.00"
        }
       },
       "required": [
        "kind",
        "amount"
       ]
      }
     },
     "previous_names": {
      "type": "array",
      "description": "Other names orders used for this charge in the period, oldest first, with the first and last business day each was used (\"Called {name} before {date}\").",
      "items": {
       "type": "object",
       "properties": {
        "name": {
         "type": "string"
        },
        "first_day": {
         "type": "string",
         "format": "date"
        },
        "last_day": {
         "type": "string",
         "format": "date"
        }
       },
       "required": [
        "name",
        "first_day",
        "last_day"
       ]
      }
     }
    },
    "required": [
     "charge_id",
     "name",
     "kind",
     "deleted",
     "note",
     "total",
     "by_kind",
     "previous_names"
    ]
   },
   "SalesItem": {
    "type": "object",
    "properties": {
     "item_id": {
      "type": "string",
      "format": "uuid"
     },
     "item_name": {
      "type": "string",
      "example": "Nasi"
     },
     "sold_count": {
      "type": "string",
      "example": "2",
      "description": "Quantity sold in the period."
     },
     "amount": {
      "type": "string",
      "example": "50.00",
      "description": "The value this page is ordered by. Quantity for most_items_sold, otherwise a 2 dp decimal."
     },
     "item_sales": {
      "type": "string",
      "example": "40000.00",
      "description": "PAN-391. Item sales (Penjualan menu): quantity x unit price of this item's lines in the period, before refunds, on every sort (amount only equals it under most_sales). 2 dp."
     },
     "item_sales_after_refunds": {
      "type": "string",
      "example": "90.00",
      "description": "PAN-391 (0075). Gross sales (line revenue) minus this item's menu-price share of completed refunds (what net_sales was before 0075). The line revenue is dated by the order's close day and each refund's share by the day the refund was paid (paid_at in the merchant timezone), so a period can show an item with sold_count 0 and a negative value. The items add up to totals.item_sales_after_refunds."
     },
     "revenue_charges": {
      "type": "string",
      "example": "4.50",
      "description": "PAN-391 (0075). This item's share of the bill's revenue charges (order_charges kind revenue, the kind the order took), close day, minus that share of completed refunds (refund x share / (bill items + bill charges)), paid day. A charge with stored per-line amounts (orders confirmed since 0073) follows those lines, scaled to the bill amount; older orders spread it by line revenue. Tax, collected for others and Unclassified charges never reach items. 2 dp."
     },
     "net_sales": {
      "type": "string",
      "example": "94.50",
      "description": "PAN-391 Net sales (0075) = item_sales_after_refunds + revenue_charges. Over a period the items add up to totals.net_sales, which equals cashflow totals.net_sales up to rounding. Ranks most_net_sales and is the base of gross_profit. May be negative on a refund-only day."
     },
     "cost_of_sales": {
      "type": "string",
      "example": "40.00",
      "description": "Ingredient cost of the lines sold in the period. Omitted without costs.view."
     },
     "gross_profit": {
      "type": "string",
      "example": "50.00",
      "description": "net_sales minus cost_of_sales (waste is not subtracted). Omitted without costs.view."
     },
     "cost_status": {
      "type": "string",
      "enum": [
       "ok",
       "no_recipe",
       "no_ingredient_cost"
      ],
      "description": "PAN-391. Why the cost is what it is. no_recipe: the item has no recipe, so no ingredient cost (\"Belum ada resep\"). no_ingredient_cost: it has a recipe but the period cost is 0, usually because no purchase has been recorded for its ingredients so their average cost is 0 (\"Bahan belum ada harga beli\"). ok otherwise, including an item with a recipe and sold_count 0 (only refunds in the period)."
     }
    },
    "required": [
     "item_id",
     "item_name",
     "sold_count",
     "amount",
     "item_sales",
     "item_sales_after_refunds",
     "revenue_charges",
     "net_sales",
     "cost_status"
    ]
   },
   "FcmDeviceRegisterRequest": {
    "type": "object",
    "properties": {
     "token": {
      "type": "string",
      "maxLength": 4096,
      "description": "FCM registration token from the Firebase JS SDK getToken(). No whitespace."
     },
     "platform": {
      "type": "string",
      "enum": [
       "web"
      ],
      "default": "web"
     }
    },
    "required": [
     "token"
    ],
    "example": {
     "token": "fXk3cJ9pQ0u6Y2b8Rz1sTq:APA91bH-example-registration-token",
     "platform": "web"
    }
   },
   "FcmDeviceTokenRequest": {
    "type": "object",
    "properties": {
     "token": {
      "type": "string",
      "maxLength": 4096
     }
    },
    "required": [
     "token"
    ],
    "example": {
     "token": "fXk3cJ9pQ0u6Y2b8Rz1sTq:APA91bH-example-registration-token"
    }
   },
   "FcmDevice": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "format": "uuid"
     },
     "platform": {
      "type": "string",
      "enum": [
       "web"
      ]
     },
     "role": {
      "type": "string",
      "enum": [
       "owner",
       "manager",
       "cashier",
       "kitchen"
      ],
      "description": "Role of the membership the token is registered to."
     },
     "push_active": {
      "type": "boolean",
      "description": "True when the server has a valid FCM key and will send kitchen_queue_changed nudges."
     },
     "created_at": {
      "type": "string",
      "format": "date-time"
     },
     "updated_at": {
      "type": "string",
      "format": "date-time"
     }
    },
    "required": [
     "id",
     "platform",
     "role",
     "push_active",
     "created_at",
     "updated_at"
    ]
   },
   "CashflowPeriod": {
    "type": "object",
    "description": "Comparison period of the same length as from..to that ends the day before from. Added in PAN-39; older clients ignore it.",
    "properties": {
     "from": {
      "type": "string",
      "format": "date",
      "example": "2026-09-22"
     },
     "to": {
      "type": "string",
      "format": "date",
      "example": "2026-09-28"
     },
     "days": {
      "type": "integer",
      "minimum": 1,
      "example": 7,
      "description": "Number of days in the period (to - from + 1), equal to the length of the selected range."
     },
     "rows": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/CashflowDay"
      },
      "description": "Buckets of the previous period, grouped by the same group_by. Empty when the period has no activity."
     },
     "totals": {
      "$ref": "#/components/schemas/CashflowDay"
     }
    },
    "required": [
     "from",
     "to",
     "days",
     "rows",
     "totals"
    ]
   },
   "ImageUploadUrlRequest": {
    "type": "object",
    "properties": {
     "content_type": {
      "type": "string",
      "enum": [
       "image/jpeg",
       "image/png",
       "image/webp"
      ]
     },
     "size_bytes": {
      "type": "integer",
      "minimum": 1,
      "maximum": 1048576,
      "example": 204800
     }
    },
    "required": [
     "content_type",
     "size_bytes"
    ]
   },
   "ImageUploadUrlResponse": {
    "type": "object",
    "properties": {
     "upload_url": {
      "type": "string",
      "example": "https://<account>.r2.cloudflarestorage.com/<bucket>/merchants/.../x.png?X-Amz-...",
      "description": "Presigned PUT URL (S3 API on R2), expires in 5 minutes."
     },
     "method": {
      "type": "string",
      "example": "PUT"
     },
     "headers": {
      "type": "object",
      "additionalProperties": {
       "type": "string"
      },
      "example": {
       "Content-Type": "image/png"
      },
      "description": "Headers the client MUST send unchanged with the PUT (Content-Type and Content-Length are part of the signature)."
     },
     "object_key": {
      "type": "string",
      "example": "merchants/<business_code>/menu-items/<id>/<uuid>.png"
     },
     "expires_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     }
    },
    "required": [
     "upload_url",
     "method",
     "headers",
     "object_key",
     "expires_at"
    ]
   },
   "ImageConfirmRequest": {
    "type": "object",
    "properties": {
     "object_key": {
      "type": "string",
      "example": "merchants/<business_code>/menu-items/<id>/<uuid>.png"
     }
    },
    "required": [
     "object_key"
    ]
   },
   "Health": {
    "type": "object",
    "description": "Liveness body from `GET /healthz`. It has no `db` field.",
    "properties": {
     "status": {
      "type": "string",
      "example": "ok"
     },
     "env": {
      "type": "string",
      "example": "staging"
     },
     "version": {
      "type": "string",
      "example": "0.1.0"
     }
    }
   },
   "Ready": {
    "type": "object",
    "description": "Readiness body from `GET /readyz`.",
    "properties": {
     "status": {
      "type": "string",
      "enum": [
       "ok",
       "db_unavailable"
      ],
      "example": "ok"
     },
     "env": {
      "type": "string",
      "example": "staging"
     },
     "version": {
      "type": "string",
      "example": "0.1.0"
     },
     "db": {
      "type": "string",
      "enum": [
       "ok",
       "unavailable"
      ],
      "example": "ok"
     }
    }
   },
   "StockShortage": {
    "type": "object",
    "properties": {
     "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "ingredient_name": {
      "type": "string",
      "example": "Coffee beans"
     },
     "unit": {
      "type": "string",
      "example": "g"
     },
     "needed": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Decimal string, up to 3 dp."
     },
     "available": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Stock minus what is already reserved by preparing items."
     },
     "short_by": {
      "type": "string",
      "pattern": "^\\d+(\\.\\d{1,3})?$",
      "example": "18.000",
      "description": "Decimal string, up to 3 dp."
     },
     "order_item_ids": {
      "type": "array",
      "items": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "Items of the round that depend on this ingredient; offer these for cancellation."
     }
    }
   },
   "StockCheckRequest": {
    "type": "object",
    "properties": {
     "items": {
      "type": "array",
      "maxItems": 200,
      "items": {
       "type": "object",
       "properties": {
        "menu_item_id": {
         "type": "string",
         "format": "uuid"
        },
        "quantity": {
         "type": "integer",
         "minimum": 1,
         "maximum": 100000
        }
       }
      }
     },
     "order_id": {
      "type": "string",
      "format": "uuid",
      "description": "With no items, check the placed items of this order's round_no."
     },
     "round_no": {
      "type": "integer",
      "minimum": 1,
      "default": 1
     }
    }
   },
   "StockCheck": {
    "type": "object",
    "properties": {
     "lines": {
      "type": "array",
      "description": "One per requested line, in the order sent.",
      "items": {
       "type": "object",
       "properties": {
        "menu_item_id": {
         "type": "string",
         "format": "uuid"
        },
        "quantity": {
         "type": "integer"
        },
        "can_make": {
         "type": "integer"
        },
        "short_quantity": {
         "type": "integer",
         "description": "quantity - can_make."
        },
        "limited_by_ingredient_id": {
         "type": "string",
         "format": "uuid",
         "nullable": true
        },
        "est_cost_full": {
         "type": "string",
         "nullable": true,
         "example": "700.00",
         "description": "PAN-86. Owner and manager only (absent for cashier). Cost of the full quantity at avg_unit_cost. Null when the item has no recipe or a material has no known cost."
        },
        "est_cost_adjusted": {
         "type": "string",
         "nullable": true,
         "example": "625.00",
         "description": "PAN-86. Owner and manager only. Cost of what stock covers, per material."
        }
       }
      }
     },
     "ingredients": {
      "type": "array",
      "description": "Every material the lines use, by name.",
      "items": {
       "type": "object",
       "properties": {
        "ingredient_id": {
         "type": "string",
         "format": "uuid"
        },
        "ingredient_name": {
         "type": "string"
        },
        "unit": {
         "type": "string"
        },
        "needed": {
         "type": "string",
         "example": "10000.000"
        },
        "available": {
         "type": "string",
         "example": "8500.000"
        },
        "short_by": {
         "type": "string",
         "example": "1500.000"
        },
        "lines": {
         "type": "array",
         "items": {
          "type": "object",
          "properties": {
           "menu_item_id": {
            "type": "string",
            "format": "uuid"
           },
           "can_make": {
            "type": "integer"
           }
          }
         }
        }
       }
      }
     }
    }
   },
   "ShortageLine": {
    "type": "object",
    "properties": {
     "order_item_id": {
      "type": "string",
      "format": "uuid"
     },
     "menu_item_id": {
      "type": "string",
      "format": "uuid"
     },
     "quantity": {
      "type": "integer"
     },
     "can_make": {
      "type": "integer",
      "description": "How many of quantity the stock covers (0 to quantity)."
     },
     "short_quantity": {
      "type": "integer",
      "description": "quantity - can_make."
     },
     "limited_by_ingredient_id": {
      "type": "string",
      "format": "uuid",
      "nullable": true,
      "description": "The material that limits this line; null when nothing is short."
     }
    }
   },
   "StockShortageError": {
    "type": "object",
    "properties": {
     "error": {
      "type": "object",
      "properties": {
       "code": {
        "type": "string",
        "enum": [
         "STOCK_SHORTAGE"
        ]
       },
       "message": {
        "type": "string",
        "example": "Not enough stock for 1 ingredient"
       },
       "round_no": {
        "type": "integer"
       },
       "shortages": {
        "type": "array",
        "items": {
         "$ref": "#/components/schemas/StockShortage"
        }
       },
       "lines": {
        "type": "array",
        "description": "PAN-85. Every line of the round, in the order they take stock.",
        "items": {
         "$ref": "#/components/schemas/ShortageLine"
        }
       },
       "shortage_token": {
        "type": "string",
        "description": "Proves the caller saw this exact list. Changes when stock or the remaining items change.",
        "example": "9f2c..."
       },
       "token_stale": {
        "type": "boolean",
        "description": "True when the request set allow_partial (or its old name acknowledge_shortages, still accepted) with a shortage_token that is missing or no longer matches. Re-offer the fresh list and token."
       },
       "cancelled_item_ids": {
        "type": "array",
        "items": {
         "type": "string",
         "format": "uuid",
         "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
        },
        "description": "Items cancelled by this request before the re-check (cancellations persist)."
       },
       "request_id": {
        "type": "string",
        "example": "req_01HX..."
       }
      },
      "required": [
       "code",
       "message",
       "shortages",
       "shortage_token"
      ]
     }
    },
    "required": [
     "error"
    ]
   },
   "OrderConfirm": {
    "type": "object",
    "properties": {
     "round_no": {
      "type": "integer",
      "minimum": 1,
      "description": "Round to confirm. Default: the latest round that still has placed items."
     },
     "allow_partial": {
      "type": "boolean",
      "default": false,
      "description": "Process the round with the remaining stock (PAN-85). Requires shortage_token from the latest STOCK_SHORTAGE response."
     },
     "acknowledge_shortages": {
      "type": "boolean",
      "default": false,
      "description": "Old name of allow_partial; either one set to true has the same effect."
     },
     "shortage_token": {
      "type": "string",
      "example": "9f2c..."
     },
     "cancel_item_ids": {
      "type": "array",
      "items": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      },
      "description": "Out-of-stock items to cancel first (status cancelled, cancel_reason out_of_stock). Every id must be a placed item of THIS order, round and merchant, else 422 INVALID_CANCEL_ITEMS and nothing changes."
     },
     "removed_charge_ids": {
      "type": "array",
      "items": {
       "type": "string",
       "format": "uuid"
      },
      "description": "PAN-129. Default-on charges to leave off this order (kept on the order with removed=true and amount 0). A charge with cashier_can_remove=false can only be removed by the owner or a manager, else 403 `charge_not_removable`."
     },
     "added_charge_ids": {
      "type": "array",
      "items": {
       "type": "string",
       "format": "uuid"
      },
      "description": "PAN-129. Default-off charges to add to this order."
     }
    },
    "description": "Empty body = plain confirm with stock check. PAN-129: the first successful confirm stores the order charges (every active default-on charge minus removed_charge_ids plus added_charge_ids). Later confirms keep them unless either list is sent, which rebuilds the selection the same way. Every id must be an active charge of this business, removed ids default-on and added ids default-off, else 422 `invalid_charge_id`; charge checks run before anything is confirmed."
   },
   "OrderConfirmResult": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "enum": [
       "confirmed",
       "nothing_confirmed"
      ]
     },
     "round_no": {
      "type": "integer"
     },
     "confirmed_item_ids": {
      "type": "array",
      "items": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      }
     },
     "cancelled_item_ids": {
      "type": "array",
      "items": {
       "type": "string",
       "format": "uuid",
       "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
      }
     },
     "overridden": {
      "type": "boolean"
     },
     "order_status": {
      "type": "string",
      "enum": [
       "open",
       "cancelled"
      ],
      "description": "cancelled only when every item of the order ended up cancelled and no payment exists."
     },
     "order": {
      "$ref": "#/components/schemas/Order"
     }
    }
   },
   "QueueItem": {
    "type": "object",
    "properties": {
     "order_item_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "menu_item_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "name": {
      "type": "string",
      "example": "Nasi Goreng"
     },
     "quantity": {
      "type": "integer",
      "example": 2
     },
     "note": {
      "type": "string",
      "example": "pedas",
      "nullable": true
     },
     "status": {
      "type": "string",
      "enum": [
       "placed",
       "preparing",
       "served"
      ]
     },
     "short_quantity": {
      "type": "integer",
      "minimum": 0,
      "description": "PAN-85. How many of quantity stock could not cover; 0 when nothing is short."
     },
     "short_ingredient_name": {
      "type": "string",
      "nullable": true,
      "example": "Chicken",
      "description": "PAN-85. The first material that ran short; null when nothing is short."
     },
     "ready_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "PAN-87. When the line was ticked Ready; null when not ready."
     },
     "ready_by_name": {
      "type": "string",
      "nullable": true,
      "description": "PAN-87, PAN-343. Name of who ticked it Ready (copied at tick time, kept if the person is removed; same name rule as OrderItem.ready_by_name); null when not ready."
     },
     "served_at": {
      "type": "string",
      "format": "date-time",
      "nullable": true,
      "description": "PAN-87. When the line was served; null while preparing."
     },
     "served_by_name": {
      "type": "string",
      "nullable": true,
      "description": "PAN-87, PAN-343. Name of who served it (copied at serve time, kept if the person is removed; same name rule as OrderItem.served_by_name); null while preparing."
     }
    }
   },
   "QueueRound": {
    "type": "object",
    "properties": {
     "order_id": {
      "type": "string",
      "format": "uuid",
      "example": "3f2b8c1e-9a4d-4e6b-8f21-5c7d0a1b2e34"
     },
     "order_no": {
      "type": "integer",
      "example": 12,
      "description": "Per-merchant order number."
     },
     "table_label": {
      "type": "string",
      "example": "T7",
      "nullable": true
     },
     "round_no": {
      "type": "integer",
      "example": 2
     },
     "round_added_at": {
      "type": "string",
      "format": "date-time",
      "example": "2026-10-04T08:30:00Z"
     },
     "age_seconds": {
      "type": "integer",
      "format": "int64",
      "example": 420
     },
     "items": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/QueueItem"
      }
     },
     "line_count": {
      "type": "integer",
      "example": 3,
      "description": "PAN-87. Lines of the round that are preparing or served (cancelled lines are not counted)."
     },
     "ready_count": {
      "type": "integer",
      "example": 2,
      "description": "PAN-87. Of those, lines that are ready or served."
     },
     "served_count": {
      "type": "integer",
      "example": 1,
      "description": "PAN-87. Of those, lines that are served."
     }
    },
    "description": "One open order round that still has a preparing item (from v_order_queue), oldest first. Placed items are not included until the round is confirmed. Served lines of such a round stay in items; cancelled lines, rounds with no preparing line, and closed or cancelled orders are not included."
   }
  }
 }
}