apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "mautrix-whatsapp.fullname" . }}
  labels:
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
    app.kubernetes.io/name: {{ template "mautrix-whatsapp.name" . }}
data:
  config.yaml: |
    homeserver:
      address: {{ .Values.homeserver.address }}
      domain: {{ .Values.homeserver.domain }}

    appservice:
      address: http://{{ include "mautrix-whatsapp.fullname" . }}:{{ .Values.service.port }}

      hostname: 0.0.0.0
      port: {{ .Values.service.port }}

      {{- if .Values.postgresql.enabled }}
      database:
        type: postgres
        uri: "postgres://postgres:{{ .Values.postgresql.postgresqlPassword }}@{{ .Release.Name }}-postgresql/{{ .Values.postgresql.postgresqlDatabase }}?sslmode=disable"
      {{- else }}
      database:
        {{- toYaml .Values.appservice.database | nindent 8 }}
      {{- end }}

      id: {{ .Values.appservice.id }}
      bot:
        username: {{ .Values.appservice.botUsername }}
        displayname: {{ .Values.appservice.botDisplayname }}
        avatar:  {{ .Values.appservice.botAvatar }}

      as_token: {{ .Values.appservice.asToken }}
      hs_token: {{ .Values.appservice.hsToken }}

    bridge:
      {{- toYaml .Values.bridge | nindent 6 }}

    logging:
      {{- toYaml .Values.logging | nindent 6 }}
  registration.yaml: ""