pick( $doctorId, $clinicId, fn (int $id): bool => $this->contracts->findActiveByTenant('doctor', $id) !== [], ); } /** @return array{0: string, 1: int} */ public function forVisitPrice(int $doctorId, ?int $clinicId): array { return $this->pick( $doctorId, $clinicId, fn (int $id): bool => $this->pricing->findByEntity('doctor', $id) !== [], ); } /** @return array{0: string, 1: int} */ public function forServiceCategories(int $doctorId, ?int $clinicId): array { return $this->pick( $doctorId, $clinicId, fn (int $id): bool => $this->categorySettings->enabledMapFor('doctor', $id) !== [], ); } /** * @param callable(int):bool $doctorHasOwn * @return array{0: string, 1: int} */ private function pick(int $doctorId, ?int $clinicId, callable $doctorHasOwn): array { if ($clinicId === null || $doctorHasOwn($doctorId)) { return ['doctor', $doctorId]; } return ['clinic', $clinicId]; } }