{{- if .Values.backupsEnabled }}

{{- if typeIs "[]interface {}" .Values.configuration.backupStorageLocation }}
{{- range .Values.configuration.backupStorageLocation }}
---
apiVersion: velero.io/v1
kind: BackupStorageLocation
metadata:
  name: {{ .name | default "default" }}
  namespace: {{ $.Release.Namespace }}
  {{- with .annotations }}
  annotations:
      {{- range $key, $value := . }}
    {{- $key | nindent 4 }}: {{ $value | quote }}
    {{- end }}
  {{- end }}
  labels:
    app.kubernetes.io/name: {{ include "velero.name" $ }}
    app.kubernetes.io/instance: {{ $.Release.Name }}
    app.kubernetes.io/managed-by: {{ $.Release.Service }}
    helm.sh/chart: {{ include "velero.chart" $ }}
spec:
  {{- if not (empty .credential) }}
  credential:
    {{- with .credential.name }}
    name: {{ . }}
    {{- end }}
    {{- with .credential.key }}
    key: {{ . }}
    {{- end }}
  {{- end }}
  provider: {{ .provider }}
  accessMode: {{ .accessMode | default "ReadWrite" }}
  {{- with .default }}
  default: {{ . }}
  {{- end }}
  {{- with .validationFrequency }}
  validationFrequency: {{ . }}
  {{- end }}
  objectStorage:
    bucket: {{ .bucket | quote }}
    {{- with .prefix }}
    prefix: {{ . | quote }}
    {{- end }}
    {{- with .caCert }}
    caCert: {{ . }}
    {{- end }}
{{- with .config }}
  config:
{{- range $key, $value := . }}
{{- $key | nindent 4 }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
