model = new TableModel(); } public function __invoke(ServerRequestInterface $request) { $body = json_decode((string)$request->getBody(), true) ?? []; $companyId = $body['company_id'] ?? null; $tableNumber = $body['table_number'] ?? null; $statusId = $body['status_id'] ?? null; if (!$companyId || !$tableNumber || !$statusId) { return ResponseLib::sendFail("Missing required fields", [], "E_VALIDATE")->withStatus(400); } if (!$this->model->companyExists((int)$companyId)) { return ResponseLib::sendFail("Invalid company_id", [], "E_VALIDATE")->withStatus(400); } if (!$this->model->statusExists((int)$statusId)) { return ResponseLib::sendFail("Invalid status_id", [], "E_VALIDATE")->withStatus(400); } $created = $this->model->createTable((int)$companyId, (string)$tableNumber, (int)$statusId); return $created ? ResponseLib::sendOk(['created' => true]) : ResponseLib::sendFail("Failed to create table", [], "E_DATABASE")->withStatus(500); } }