{{- if .Values.ingress.enabled -}}
# Frontend Ingress (peikarband.ir -> port 3000)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ include "peikarband.fullname" . }}-frontend
  labels:
    {{- include "peikarband.labels" . | nindent 4 }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.ingress.className }}
  ingressClassName: {{ .Values.ingress.className }}
  {{- end }}
  {{- if .Values.ingress.tls }}
  tls:
    {{- range .Values.ingress.tls }}
    - hosts:
        {{- range .hosts }}
        - {{ . | quote }}
        {{- end }}
      secretName: {{ .secretName }}
    {{- end }}
  {{- end }}
  rules:
    {{- range .Values.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            pathType: {{ .pathType }}
            backend:
              service:
                name: {{ include "peikarband.fullname" $ }}
                port:
                  number: {{ $.Values.service.frontend.port }}
          {{- end }}
    {{- end }}
{{- end }}

{{- if .Values.ingress.apiEnabled -}}
# Backend API Ingress (api.peikarband.ir -> port 8000)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ include "peikarband.fullname" . }}-api
  labels:
    {{- include "peikarband.labels" . | nindent 4 }}
  {{- with .Values.ingress.apiAnnotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.ingress.className }}
  ingressClassName: {{ .Values.ingress.className }}
  {{- end }}
  {{- if .Values.ingress.apiTls }}
  tls:
    {{- range .Values.ingress.apiTls }}
    - hosts:
        {{- range .hosts }}
        - {{ . | quote }}
        {{- end }}
      secretName: {{ .secretName }}
    {{- end }}
  {{- end }}
  rules:
    {{- range .Values.ingress.apiHosts }}
    - host: {{ .host | quote }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            pathType: {{ .pathType }}
            backend:
              service:
                name: {{ include "peikarband.fullname" $ }}
                port:
                  number: {{ $.Values.service.backend.port }}
          {{- end }}
    {{- end }}
{{- end }}
