{{- $root := . -}}
{{- range $ingress, $ingressValue := .Values.ingresses }}
{{- if $ingressValue.enabled }}
---
apiVersion: {{ include "owgwui.ingress.apiVersion" $root }}
kind: Ingress
metadata:
  name: {{ include "owgwui.fullname" $root }}-{{ $ingress }}
  labels:
    app.kubernetes.io/name: {{ include "owgwui.name" $root }}
    helm.sh/chart: {{ include "owgwui.chart" $root }}
    app.kubernetes.io/instance: {{ $root.Release.Name }}
    app.kubernetes.io/managed-by: {{ $root.Release.Service }}
  {{- with $ingressValue.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}

spec:
{{- if $ingressValue.className }}
  ingressClassName: {{ $ingressValue.className }}
{{- end }}
{{- if $ingressValue.tls }}
  tls:
  {{- range $ingressValue.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ tpl .secretName $root }}
  {{- end }}
{{- end }}

  rules:
  {{- range $ingressValue.hosts }}
  - host: {{ . | quote }}
    http:
      paths:
      {{- range $ingressValue.paths }}
        - path: {{ .path }}
          {{- if $root.Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
          pathType: {{ .pathType | default "ImplementationSpecific" }}
          {{- end }}
          backend:
            {{- if $root.Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
            service:
              name: {{ include "owgwui.fullname" $root }}-{{ .serviceName }}
              port:
              {{- if kindIs "string" .servicePort }}
                name: {{ .servicePort }}
              {{- else }}
                number: {{ .servicePort }}
              {{- end }}
            {{- else }}
            serviceName: {{ include "owgwui.fullname" $root }}-{{ .serviceName }}
            servicePort: {{ .servicePort }}
            {{- end }}
      {{- end }}
  {{- end }}

{{- end }}

{{- end }}
