---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .NAME }}
  namespace: {{ .NAMESPACE }}
spec:
  replicas: {{ .REPLICAS }}
  selector:
    matchLabels:
      app: {{ .NAME }}
  template:
    metadata:
      labels:
        app: {{ .NAME }}
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8000"
    spec:
      containers:
        - name: {{ .NAME }}
          env:
            - name: ENVIRONMENT
              value: {{ .ENVIRONMENT }}
            - name: PORT
              value: "8000"
            - name: LOG_LEVEL
              value: "INFO"
            - name: MONGODB_URI
              valueFrom:
                secretKeyRef:
                  name: mongodb
                  key: mongo-uri
            - name: MONGODB_DATABASE
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: mongo-database
            - name: PPROF_ENABLED
              value: "{{ .PPROF_ENABLED }}"
            - name: P2P_NETWORK
              value: {{ .P2P_NETWORK }}
            - name: ANKR_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: ankr-url
            - name: ANKR_REQUESTS_PER_SECOND
              value: "{{ .ANKR_REQUESTS_PER_SECOND }}"
            - name: TERRA_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: terra-url
            - name: TERRA_REQUESTS_PER_SECOND
              value: "{{ .TERRA_REQUESTS_PER_SECOND }}"
            - name: APTOS_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: aptos-url
            - name: APTOS_REQUESTS_PER_SECOND
              value: "{{ .APTOS_REQUESTS_PER_SECOND }}"
            - name: OASIS_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: oasis-url
            - name: OASIS_REQUESTS_PER_SECOND
              value: "{{ .OASIS_REQUESTS_PER_SECOND }}"
            - name: MOONBEAM_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: moonbeam-url
            - name: MOONBEAM_REQUESTS_PER_SECOND
              value: "{{ .MOONBEAM_REQUESTS_PER_SECOND }}"
            - name: CELO_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: celo-url
            - name: CELO_REQUESTS_PER_SECOND
              value: "{{ .CELO_REQUESTS_PER_SECOND }}"
            - name: OPTIMISM_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: optimism-url
            - name: OPTIMISM_REQUESTS_PER_SECOND
              value: "{{ .OPTIMISM_REQUESTS_PER_SECOND }}"
            - name: ARBITRUM_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: arbitrum-url
            - name: ARBITRUM_REQUESTS_PER_SECOND
              value: "{{ .ARBITRUM_REQUESTS_PER_SECOND }}"
            - name: BASE_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: base-url
            - name: BASE_REQUESTS_PER_SECOND
              value: "{{ .BASE_REQUESTS_PER_SECOND }}"
            - name: ETHEREUM_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: ethereum-url
            - name: ETHEREUM_REQUESTS_PER_SECOND
              value: "{{ .ETHEREUM_REQUESTS_PER_SECOND }}"
            - name: AVALANCHE_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: avalanche-url
            - name: AVALANCHE_REQUESTS_PER_SECOND
              value: "{{ .AVALANCHE_REQUESTS_PER_SECOND }}"
            - name: POLYGON_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: polygon-url
            - name: POLYGON_REQUESTS_PER_SECOND
              value: "{{ .POLYGON_REQUESTS_PER_SECOND }}"
{{ if eq .P2P_NETWORK "testnet" }}
            - name: BASE_SEPOLIA_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: base-sepolia-url
            - name: BASE_SEPOLIA_REQUESTS_PER_SECOND
              value: "{{ .BASE_SEPOLIA_REQUESTS_PER_SECOND }}"
            - name: ETHEREUM_SEPOLIA_URL
              valueFrom:
                secretKeyRef:
                  name: blockchain
                  key: ethereum-sepolia-url
            - name: ETHEREUM_SEPOLIA_REQUESTS_PER_SECOND
              value: "{{ .ETHEREUM_SEPOLIA_REQUESTS_PER_SECOND }}"
{{ end }}
            - name: ALERT_API_KEY
              valueFrom:
                secretKeyRef:
                  name: opsgenie
                  key: api-key
            - name: ALERT_ENABLED
              value: "{{ .ALERT_ENABLED }}"
          image: {{ .IMAGE_NAME }}
          imagePullPolicy: Always
          livenessProbe:
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
            failureThreshold: 4
            httpGet:
              path: /api/health
              port: 8000
          readinessProbe:
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 1
            failureThreshold: 2
            httpGet:
              path: /api/ready
              port: 8000
          resources:
            limits:
              cpu: {{ .RESOURCES_LIMITS_CPU }}
              memory: {{ .RESOURCES_LIMITS_MEMORY }}
            requests:
              cpu: {{ .RESOURCES_REQUESTS_CPU }}
              memory: {{ .RESOURCES_REQUESTS_MEMORY }}
      restartPolicy: Always
      terminationGracePeriodSeconds: 45