{{- if .Values.frontend.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ .Release.Name }}
  namespace: {{ .Values.global.namespace }}
  labels:
    app: {{ .Release.Name }}
  {{- with .Values.frontend.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.frontend.ingress.className }}
  ingressClassName: {{ .Values.frontend.ingress.className }}
  {{- end }}
  rules:
    # Frontend rule
    {{- range .Values.frontend.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            pathType: {{ .pathType }}
            backend:
              service:
                name: {{ $.Release.Name }}-{{ $.Values.frontend.name }}
                port:
                  number: {{ $.Values.frontend.service.port }}
          {{- end }}
    {{- end }}
    # Backend API rule
    {{- range .Values.backend.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            pathType: {{ .pathType }}
            backend:
              service:
                name: {{ $.Release.Name }}-{{ $.Values.backend.name }}
                port:
                  number: {{ $.Values.backend.service.port }}
          {{- end }}
    {{- end }}
{{- end }}
