{{- if eq .Values.auth.mode "basic" }}
{{- if not .Values.auth.basic.existingSecret }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "nextcloud-mcp-server.fullname" . }}-basic-auth
  labels:
    {{- include "nextcloud-mcp-server.labels" . | nindent 4 }}
type: Opaque
data:
  {{ .Values.auth.basic.usernameKey }}: {{ .Values.auth.basic.username | b64enc | quote }}
  {{ .Values.auth.basic.passwordKey }}: {{ .Values.auth.basic.password | b64enc | quote }}
{{- end }}
{{- end }}
---
{{- if eq .Values.auth.mode "multi-user-basic" }}
{{- if and .Values.auth.multiUserBasic.enableOfflineAccess (not .Values.auth.multiUserBasic.existingSecret) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "nextcloud-mcp-server.fullname" . }}-multi-user-basic
  labels:
    {{- include "nextcloud-mcp-server.labels" . | nindent 4 }}
type: Opaque
data:
  {{ .Values.auth.multiUserBasic.tokenEncryptionKeyKey }}: {{ .Values.auth.multiUserBasic.tokenEncryptionKey | b64enc | quote }}
  {{- if .Values.auth.multiUserBasic.clientId }}
  {{ .Values.auth.multiUserBasic.clientIdKey }}: {{ .Values.auth.multiUserBasic.clientId | b64enc | quote }}
  {{ .Values.auth.multiUserBasic.clientSecretKey }}: {{ .Values.auth.multiUserBasic.clientSecret | b64enc | quote }}
  {{- end }}
{{- end }}
{{- end }}
---
{{- if eq .Values.auth.mode "oauth" }}
{{- if and .Values.auth.oauth.clientId (not .Values.auth.oauth.existingSecret) }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "nextcloud-mcp-server.fullname" . }}-oauth
  labels:
    {{- include "nextcloud-mcp-server.labels" . | nindent 4 }}
type: Opaque
data:
  {{ .Values.auth.oauth.clientIdKey }}: {{ .Values.auth.oauth.clientId | b64enc | quote }}
  {{ .Values.auth.oauth.clientSecretKey }}: {{ .Values.auth.oauth.clientSecret | b64enc | quote }}
{{- end }}
{{- end }}
---
{{- if eq .Values.auth.mode "login-flow" }}
{{- if not .Values.auth.loginFlow.existingSecret }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "nextcloud-mcp-server.fullname" . }}-login-flow
  labels:
    {{- include "nextcloud-mcp-server.labels" . | nindent 4 }}
type: Opaque
data:
  {{ .Values.auth.loginFlow.tokenEncryptionKeyKey }}: {{ .Values.auth.loginFlow.tokenEncryptionKey | b64enc | quote }}
{{- end }}
{{- end }}
