{{- /*
  Bootstrap secrets for development only.
  In production, use an external secret manager (Vault, SealedSecrets, External Secrets).
*/ -}}

{{- /*
  Bootstrap secrets for development only.
  In production, use an external secret manager (Vault, SealedSecrets, External Secrets).
*/ -}}

{{- $secrets := .Values.secrets | default dict -}}
{{- /* Always render Secret (helm.sh/resource-policy: keep prevents deletion on upgrade) */ -}}
{{- /* Set secrets.enabled: false to disable */ -}}
{{- if ne $secrets.enabled false -}}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "gitdata.fullname" . }}-secrets
  namespace: {{ include "gitdata.namespace" . }}
  labels:
    app.kubernetes.io/name: {{ .Chart.Name }}
    app.kubernetes.io/instance: {{ .Release.Name }}
  annotations:
    "helm.sh/resource-policy": keep
type: Opaque
stringData:
  {{- if $secrets.databaseUrl }}
  APP_DATABASE_URL: {{ $secrets.databaseUrl | quote }}
  {{- end }}
  {{- if $secrets.redisUrl }}
  APP_REDIS_URL: {{ $secrets.redisUrl | quote }}
  {{- end }}
  {{- if .Values.nats.enabled }}
  NATS_URL: {{ .Values.nats.url | quote }}
  {{- end }}
  {{- if $secrets.aiApiKey }}
  APP_AI_BASIC_URL: {{ $secrets.aiBasicUrl | quote }}
  APP_AI_API_KEY: {{ $secrets.aiApiKey | quote }}
  {{- end }}
  {{- if $secrets.embedApiKey }}
  APP_EMBED_MODEL_BASE_URL: {{ $secrets.embedBasicUrl | quote }}
  APP_EMBED_MODEL_API_KEY: {{ $secrets.embedApiKey | quote }}
  APP_EMBED_MODEL_NAME: {{ $secrets.embedModelName | quote }}
  {{- end }}
  {{- if and .Values.qdrant.enabled .Values.qdrant.url }}
  APP_QDRANT_URL: {{ .Values.qdrant.url | quote }}
  {{- end }}
  {{- if .Values.qdrant.apiKey }}
  APP_QDRANT_API_KEY: {{ .Values.qdrant.apiKey | quote }}
  {{- end }}
  {{- if $secrets.smtpHost }}
  APP_SMTP_HOST: {{ $secrets.smtpHost | quote }}
  APP_SMTP_PORT: {{ $secrets.smtpPort | default "587" | quote }}
  APP_SMTP_USERNAME: {{ $secrets.smtpUsername | quote }}
  APP_SMTP_PASSWORD: {{ $secrets.smtpPassword | quote }}
  APP_SMTP_FROM: {{ $secrets.smtpFrom | default $secrets.smtpUsername | quote }}
  APP_SMTP_TLS: {{ $secrets.smtpTls | default "true" | quote }}
  {{- end }}
  {{- if $secrets.sshDomain }}
  APP_SSH_DOMAIN: {{ $secrets.sshDomain | quote }}
  {{- end }}
  {{- if $secrets.sshPort }}
  APP_SSH_PORT: {{ $secrets.sshPort | quote }}
  {{- end }}
  {{- if $secrets.sshServerPrivateKey }}
  APP_SSH_SERVER_PRIVATE_KEY: {{ $secrets.sshServerPrivateKey | quote }}
  {{- end }}
  {{- range $key, $value := $secrets.extra | default dict }}
  {{ $key }}: {{ $value | quote }}
  {{- end }}
{{- end }}
