model = new ProductModel(); } public function __invoke(ServerRequestInterface $request) { $body = json_decode((string)$request->getBody(), true) ?? []; try { v::key('company_id', v::intType()->positive()) ->key('show_description', v::optional(v::boolType()), false) ->assert($body); } catch (ValidationException $e) { return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(400); } $companyId = (int) $body['company_id']; $showDescription = $body['show_description'] ?? false; $products = $this->model->getProducts($companyId, $showDescription); if ($products) { return ResponseLib::sendOk($products); } return ResponseLib::sendFail("Failed to Retrieve Products", [], "E_DATABASE")->withStatus(500); } }