{{- if .Values.rabbitmq.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "firecrawl.fullname" . }}-rabbitmq
  labels:
    app: {{ include "firecrawl.name" . }}-rabbitmq
spec:
  replicas: {{ .Values.rabbitmq.replicaCount | default 1 }}
  selector:
    matchLabels:
      app: {{ include "firecrawl.name" . }}-rabbitmq
  template:
    metadata:
      labels:
        app: {{ include "firecrawl.name" . }}-rabbitmq
    spec:
      containers:
        - name: rabbitmq
          image: {{ .Values.rabbitmq.image }}
          ports:
            - containerPort: {{ .Values.service.rabbitmq.port }}
            - containerPort: {{ .Values.service.rabbitmq.managementPort }}
          {{- if and .Values.resources.enabled .Values.rabbitmq.resources }}
          resources:
            {{- toYaml .Values.rabbitmq.resources | nindent 12 }}
          {{- end }}
          livenessProbe:
            tcpSocket:
              port: {{ .Values.service.rabbitmq.port }}
            initialDelaySeconds: 20
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 6
          readinessProbe:
            tcpSocket:
              port: {{ .Values.service.rabbitmq.port }}
            initialDelaySeconds: 10
            periodSeconds: 5
            timeoutSeconds: 3
            failureThreshold: 6
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "firecrawl.fullname" . }}-rabbitmq
spec:
  type: {{ .Values.service.rabbitmq.type }}
  selector:
    app: {{ include "firecrawl.name" . }}-rabbitmq
  ports:
    - name: amqp
      protocol: TCP
      port: {{ .Values.service.rabbitmq.port }}
      targetPort: {{ .Values.service.rabbitmq.port }}
    - name: management
      protocol: TCP
      port: {{ .Values.service.rabbitmq.managementPort }}
      targetPort: {{ .Values.service.rabbitmq.managementPort }}
{{- end }}
