protocols->findForService($this->requireItem($user, $uuid)); return $this->success($protocol?->toArray()); } #[Route('/api/v1/service-item/{uuid}/treatment-protocol', name: 'treatment_protocol_replace', methods: ['PUT'])] public function replace(#[CurrentUser] User $user, string $uuid, Request $request): JsonResponse { $data = json_decode($request->getContent(), true); if (!is_array($data)) { return $this->error(ErrorCodes::ERR_VALIDATION_001, 'بدنهٔ درخواست نامعتبر است', 422); } $protocol = $this->writer->replace($user, $this->requireItem($user, $uuid), $data); return $this->success($protocol->toArray()); } /** خاموش کردن سوییچ: پروتکل حذف می‌شود و سرویس دوباره تک‌جلسه‌ای می‌گردد. */ #[Route('/api/v1/service-item/{uuid}/treatment-protocol', name: 'treatment_protocol_delete', methods: ['DELETE'])] public function delete(#[CurrentUser] User $user, string $uuid): JsonResponse { $protocol = $this->protocols->findForService($this->requireItem($user, $uuid)); if ($protocol !== null) { $this->em->remove($protocol); $this->em->flush(); } return $this->success(null); } private function requireItem(User $user, string $uuid): ServiceItem { $item = $this->items->findByUuid($uuid); [$entityType, $entityId] = $this->branches->pair($user); if ($item === null || $item->getSection()->getEntityType() !== $entityType || $item->getSection()->getEntityId() !== $entityId ) { throw new AppException(ErrorCodes::ERR_NOT_FOUND_001, 'سرویس یافت نشد', 404); } return $item; } }