==============================================================
  CopilotKit Intelligence — Deployed!
==============================================================

{{- $fullName := include "copilot-intelligence.fullname" . }}

1. Check that all pods are running:

   kubectl get pods -l app.kubernetes.io/part-of={{ include "copilot-intelligence.name" . }} -n {{ .Release.Namespace }}

2. Verify service health:

{{- if .Values.appApi.enabled }}
   kubectl exec -n {{ .Release.Namespace }} deploy/{{ include "copilot-intelligence.componentName" (dict "root" . "component" "app-api") }} -- wget -qO- http://127.0.0.1:{{ .Values.appApi.service.port }}/api/health
{{- end }}

3. Access your services:

{{- if .Values.ingress.enabled }}
{{- if .Values.ingress.ui.host }}
   UI:       https://{{ .Values.ingress.ui.host }}
{{- end }}
{{- if .Values.ingress.api.host }}
   API Base:   https://{{ .Values.ingress.api.host }}/api
   API Health: https://{{ .Values.ingress.api.host }}/api/health
{{- end }}
{{- if and .Values.realtimeGateway.enabled .Values.ingress.realtimePlane.host }}
   Realtime:   {{ include "copilot-intelligence.realtimeClientUrl" . }}
{{- end }}

   Or check the ingress directly:
   kubectl get ingress {{ $fullName }} -n {{ .Release.Namespace }}

{{- else if eq .Values.appApi.service.type "LoadBalancer" }}

   Services are exposed via LoadBalancer (e.g. Docker Desktop):

{{- if .Values.appFrontend.enabled }}
   App Frontend:   http://localhost:{{ .Values.appFrontend.service.port }}
{{- end }}
{{- if .Values.appApi.enabled }}
   App API:        http://localhost:{{ .Values.appApi.service.port }}
{{- end }}

{{- else }}
   Ingress is disabled and services are ClusterIP. Access via port-forward:
   kubectl port-forward -n {{ .Release.Namespace }} svc/{{ include "copilot-intelligence.componentName" (dict "root" . "component" "app-frontend") }} 4300:{{ .Values.appFrontend.service.port }}
{{- end }}

{{- /* --- Warnings --- */}}
{{- $warnings := list }}
{{- if and (not .Values.database.host) (not .Values.database.existingSecret) (not .Values.postgresql.enabled) }}
{{- $warnings = append $warnings "database.host is not set and postgresql subchart is disabled. The app-api will fail to start." }}
{{- end }}
{{- if and (not .Values.redis.host) (not .Values.redis.existingSecret) (not (index .Values "redis-subchart" "enabled")) }}
{{- $warnings = append $warnings "redis.host is not set and redis subchart is disabled. Services that require Redis will fail." }}
{{- end }}
{{- /* Only the UI signs people in; API keys and service tokens need no issuer. */}}
{{- if and (not .Values.auth.issuer) (not .Values.keycloak.enabled) .Values.appFrontend.enabled }}
{{- $warnings = append $warnings "auth.issuer (OIDC issuer URL) is not set, so nobody can sign in to the UI." }}
{{- end }}
{{- if and .Values.ingress.enabled (not .Values.ingress.ui.host) }}
{{- $warnings = append $warnings "ingress.ui.host is not set. The UI will not be reachable via ingress." }}
{{- end }}
{{- if and .Values.ingress.enabled (not .Values.ingress.api.host) }}
{{- $warnings = append $warnings "ingress.api.host is not set. The API will not be reachable via ingress." }}
{{- end }}
{{- if and .Values.externalSecrets.enabled (not .Values.externalSecrets.store.name) }}
{{- $warnings = append $warnings "externalSecrets.store.name is not set. ExternalSecrets will not sync." }}
{{- end }}
{{- if and .Values.realtimeGateway.enabled .Values.ingress.enabled (not .Values.ingress.realtimePlane.host) }}
{{- $warnings = append $warnings "realtimeGateway.enabled=true but ingress.realtimePlane.host is not set. Browser WebSocket clients will need another route to the gateway." }}
{{- end }}
{{- if and .Values.realtimeGateway.enabled (not .Values.realtimeGateway.existingSecret) (not (and .Values.externalSecrets.enabled (default false .Values.externalSecrets.secrets.realtimeGateway.enabled))) (not .Values.selfHostedSecrets.enabled) (not .Values.localDevSecrets.enabled) }}
{{- $warnings = append $warnings (printf "realtimeGateway.enabled=true but no runtime Secret generator is configured. Create Secret %s-realtime-gateway with keys runner-auth-secret and secret-key-base before pods start, or configure realtimeGateway.existingSecret, externalSecrets.secrets.realtimeGateway, or selfHostedSecrets." $fullName) }}
{{- end }}
{{- if and .Values.realtimeGateway.enabled (not (and .Values.externalSecrets.enabled (default false .Values.externalSecrets.secrets.beamCookie.enabled))) (not .Values.selfHostedSecrets.enabled) (not .Values.localDevSecrets.enabled) }}
{{- $warnings = append $warnings (printf "realtimeGateway.enabled=true but no BEAM cookie Secret generator is configured. Create Secret %s with key %s before pods start, or configure externalSecrets.secrets.beamCookie or selfHostedSecrets." .Values.realtimeGateway.beam.cookieSecret.name .Values.realtimeGateway.beam.cookieSecret.key) }}
{{- end }}

{{- $retiredAttribution := ((.Values.marketplace | default dict).buyer | default dict).resourceAttribution | default dict }}
{{- if and (kindIs "map" $retiredAttribution) (or (hasKey $retiredAttribution "apiCalls") (hasKey $retiredAttribution "dedicatedAlb")) }}

NOTICE: marketplace.buyer.resourceAttribution (apiCalls, dedicatedAlb) is ignored because AWS usage attribution is always on; remove it from your values.
{{- end }}

{{- if $warnings }}

--- Configuration Warnings ---
{{ range $warnings }}
WARNING: {{ . }}
{{- end }}
{{- end }}

For documentation, see: charts/copilot-intelligence/README.md
