token()) ->acceptJson() ->timeout(12) ->withQueryParameters(['owner' => $owner]); } public function configured(): bool { return $this->token() !== '' && $this->base() !== ''; } /** * @return array */ public function status(string $owner): array { $response = $this->http($owner)->get($this->base().'/integrations/status'); $response->throw(); return (array) ($response->json('data') ?? []); } /** * @return array */ public function enable(string $owner, string $organizationName, ?string $branchName = null): array { $this->http($owner)->post($this->base().'/integrations/provision', array_filter([ 'organization_name' => $organizationName, 'branch_name' => $branchName, 'industry' => 'healthcare', ]))->throw(); return $this->syncIntegration($owner, true); } /** * @return array */ public function syncIntegration(string $owner, bool $enabled = true): array { $response = $this->http($owner)->patch($this->base().'/integrations', [ 'care_enabled' => $enabled, ]); $response->throw(); return (array) ($response->json('data') ?? []); } public function disable(string $owner): void { // Local Care setting only; Queue must be disabled separately in Queue settings. } public function isLinked(string $owner): bool { if (! $this->configured()) { return false; } try { $status = $this->status($owner); return (bool) ($status['provisioned'] ?? false) && (bool) data_get($status, 'integrations.care', false); } catch (RequestException) { return false; } } /** * @return list> */ public function counters(string $owner): array { $response = $this->http($owner)->get($this->base().'/counters'); $response->throw(); return (array) ($response->json('data') ?? []); } /** * @return array */ public function console(string $owner, string $counterUuid): array { $response = $this->http($owner)->get($this->base().'/counters/'.$counterUuid.'/console'); $response->throw(); return (array) ($response->json('data') ?? []); } /** * @param array $payload * @return array */ public function consoleAction(string $owner, string $counterUuid, array $payload): array { $response = $this->http($owner)->post($this->base().'/counters/'.$counterUuid.'/console', $payload); $response->throw(); return (array) ($response->json('data') ?? []); } /** * Best-effort specialty queue sync. Care integration API is read/console-only today, * so stubs remain Care-side until Queue exposes create-queue for service tokens. * * @param list> $stubs * @return list> */ public function syncSpecialtyQueueStubs(string $owner, array $stubs): array { if (! $this->configured() || $stubs === []) { return $stubs; } try { $existing = collect($this->counters($owner)) ->flatMap(fn ($c) => $c['queues'] ?? []) ->map(fn ($q) => strtolower((string) ($q['name'] ?? ''))) ->filter() ->all(); } catch (\Throwable) { return $stubs; } foreach ($stubs as $i => $stub) { $name = strtolower((string) ($stub['name'] ?? '')); $stubs[$i]['synced'] = $name !== '' && in_array($name, $existing, true); } return $stubs; } }