apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Values.configMapName }}
  namespace: {{ .Release.Namespace }}
  labels:
    app: metering-server
    chart: {{ include "metering-server.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  accountinfo.yaml: |-
    account:
      {{ .Values.config.account }}
    {{- if .Values.config.project }}
    project:
      {{ .Values.config.project }}
    {{- end }}
    region:
      {{ .Values.config.region }}
    logicalRegionName:
      {{ .Values.config.logicalRegionName }}
    env:
      {{ .Values.config.env }}
  meteringconfig.yaml: |-
    {{- if .Values.config.o11yRegionalDataServiceUrl }}
    o11yRegionalDataServiceUrl: {{ .Values.config.o11yRegionalDataServiceUrl }}
    {{- end }}
    auth0:
      grantType: {{ .Values.config.auth0.grantType }}
      clientID: {{ .Values.config.auth0.clientID }}
      clientSecret: {{ .Values.config.auth0.clientSecret }}
      audience: {{ .Values.config.auth0.audience }}
    databases:
      {{- range .Values.config.databases }}
      - type: {{ .type }}
        dsn: {{ .dsn }}
        use: {{ .use }}
      {{- end }}
    periodConfig:
      firstPeriod: {{ .Values.config.periodConfig.firstPeriod }}
    scheduleConfig:
      generateStatisticTaskIntervalSeconds: {{ .Values.config.scheduleConfig.generateStatisticTaskIntervalSeconds }}
      executeStatisticTaskIntervalSeconds: {{ .Values.config.scheduleConfig.executeStatisticTaskIntervalSeconds }}
      mergeStatisticIntervalHours: {{ .Values.config.scheduleConfig.mergeStatisticIntervalHours }}
      {{- if hasKey .Values.config.scheduleConfig "mergeStatisticImmediately" }}
      mergeStatisticImmediately: {{ .Values.config.scheduleConfig.mergeStatisticImmediately }}
      {{- end }}
      generateStatisticReportIntervalHours: {{ .Values.config.scheduleConfig.generateStatisticReportIntervalHours }}
      generateStatisticReportImmediately: {{ .Values.config.scheduleConfig.generateStatisticReportImmediately }}
      clearStatisticDataIntervalHours: {{ .Values.config.scheduleConfig.clearStatisticDataIntervalHours }}
      {{- if hasKey .Values.config.scheduleConfig "monthlyProportion" }}
      monthlyProportion: {{ .Values.config.scheduleConfig.monthlyProportion }}
      {{- end }}
    tasks:
      {{- range .Values.config.commonTasks }}
      - statisticClass: {{ .statisticClass | quote }}
        meteringGroup: {{ .meteringGroup | quote }}
        env: {{ .env | quote }}
      {{- end }}
      {{- range .Values.config.cloudTasks }}
      - statisticClass: {{ .statisticClass | quote }}
        meteringGroup: {{ .meteringGroup | quote }}
        env: {{ .env | quote }}
      {{- end }}
    categoryShareProportions:
      {{- range .Values.config.categoryShareProportions }}
      - cloudService: {{ .cloudService | quote }}
        category: {{ .category | quote }}
        proportion: {{ .proportion }}
      {{- end }}
