{{- if .Values.turnProber.enabled }}
apiVersion: batch/v1
kind: CronJob
metadata:
  name: {{ include "probers.fullname" . }}-turn
  labels:
    {{- include "probers.labels" . | nindent 4 }}
spec:
  schedule: "{{ .Values.turnProber.schedule }}"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      template:
        spec:
          imagePullSecrets:
{{ toYaml .Values.turnProber.imagePullSecrets | indent 12 }}
          restartPolicy: OnFailure
          containers:
          - name: turnutils-client
            image: "{{ .Values.turnProber.image.repository }}:{{ .Values.turnProber.image.tag }}"
            imagePullPolicy: {{ .Values.turnProber.image.pullPolicy }}
            command:
            - /bin/sh
            - -c
            - |
              set -e
              echo "Probing TURN server {{ .Values.turnProber.target }} via custom prober"

              # Run the custom client
              turnutils_uclient_ars -c -n 2000 -v -H 1 -R 1 \
                -u {{ .Values.turnProber.username }} \
                -w {{ .Values.turnProber.password }} \
                -p {{ .Values.turnProber.port }} \
                {{ .Values.turnProber.target }}
              

              # ORIGINAL PROBE (coturn stock invocation)
              # Run the client
              # -y: client-to-client mode (self-test, verifies relay functionality)
              # -n 5: Send 5 messages
              # -v: Verbose (useful for debugging logs)
              # Exits 0 on success, non-zero on failure
              #turnutils_uclient -v $PROTOCOL_FLAG -n 5 -y \
              #  -u {{ .Values.turnProber.username }} \
              #  -w {{ .Values.turnProber.password }} \
              #  {{ .Values.turnProber.target }}
              

              echo "TURN probe successful."
{{- end }}