{{- if not .Values.llm.existingSecret }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "turnstone.fullname" . }}-secrets
  labels:
    {{- include "turnstone.labels" . | nindent 4 }}
type: Opaque
data:
  {{- if .Values.llm.apiKey }}
  OPENAI_API_KEY: {{ .Values.llm.apiKey | b64enc | quote }}
  {{- end }}
  {{- if and .Values.postgresql.enabled .Values.postgresql.auth.password }}
  POSTGRES_PASSWORD: {{ .Values.postgresql.auth.password | b64enc | quote }}
  {{- else if and (not .Values.postgresql.enabled) .Values.database.external.password }}
  POSTGRES_PASSWORD: {{ .Values.database.external.password | b64enc | quote }}
  {{- end }}
  {{- if and .Values.auth.enabled .Values.auth.token (not .Values.auth.existingSecret) }}
  TURNSTONE_AUTH_TOKEN: {{ .Values.auth.token | b64enc | quote }}
  {{- end }}
  {{- if and .Values.redis.enabled .Values.redis.auth }}
  {{- if .Values.redis.auth.password }}
  REDIS_PASSWORD: {{ .Values.redis.auth.password | b64enc | quote }}
  {{- end }}
  {{- else if and (not .Values.redis.enabled) .Values.redis.external.password }}
  REDIS_PASSWORD: {{ .Values.redis.external.password | b64enc | quote }}
  {{- end }}
{{- end }}
