model = new TableModel(); } public function __invoke(ServerRequestInterface $request) { $body = json_decode((string)$request->getBody(), true) ?? []; $tableNumber = $body['table_number'] ?? null; $companyId = $body['company_id'] ?? null; $statusStatus = $body['status_status'] ?? null; if (!$tableNumber || !$companyId || !$statusStatus) { return ResponseLib::sendFail("Missing required fields", [], "E_VALIDATE")->withStatus(400); } $statusId = $this->model->getStatusIdByName($statusStatus); if ($statusId === null) { return ResponseLib::sendFail("Invalid status_status: '{$statusStatus}'", [], "E_VALIDATE")->withStatus(400); } $updated = $this->model->updateTableByNumber((string)$tableNumber, (int)$companyId, $statusId); return $updated ? ResponseLib::sendOk(['updated' => true]) : ResponseLib::sendFail("Failed to update status or table not found", [], "E_DATABASE")->withStatus(404); } }