{{- if and .Values.rbac.enabled .Values.rbac.serviceAccount.enabled }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
  # Define the ServiceAccount name, either from values or generated
  name: {{ default (include "formbricks.name" .) .Values.rbac.serviceAccount.name }}
  labels:
    # Standard labels for tracking the service account
    {{- include "formbricks.labels" . | nindent 4 }}

    # Additional labels if provided
    {{- with .Values.rbac.serviceAccount.additionalLabels }}
      {{- toYaml . | nindent 4 }}
    {{- end }}

  # Optional annotations for the service account
  annotations:
    {{- with .Values.rbac.serviceAccount.annotations }}
      {{- toYaml . | nindent 4 }}
    {{- end }}
{{- end }}
