fetchCompanyOrderCategorySteps = $fetchCompanyOrderCategorySteps; $this->listsCompanyCompleteOrders = $listsCompanyCompleteOrders; $this->listCompanyCancelledOrders = $listCompanyCancelledOrders; $this->listCompanyOrdersCategory = $listCompanyOrdersCategory; } /** * @param int $id * @param string $category * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection * @throws InternalServerErrorException */ public function execute(int $id, string $category){ try { switch ($category){ case OrderSteps::COMPANY_COMPLETE_CATEGORY: return $this->listsCompanyCompleteOrders->execute($id); case OrderSteps::COMPANY_CANCEL_CATEGORY: return $this->listCompanyCancelledOrders->execute($id); default: return $this->listCompanyOrdersCategory->execute($id, $this->fetchCompanyOrderCategorySteps->execute($category)); } } catch (CannotListCompanyOrderCategoryException $exception){ throw new InternalServerErrorException('Cannot list company\'s order in category because'.$exception); } } }