---
# ============================================================================
# NGINX Ingress Controller Installation (via Helm)
# ============================================================================
# Install with:
# helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
# helm repo update
# helm install ingress-nginx ingress-nginx/ingress-nginx \
#   --namespace ingress-nginx \
#   --create-namespace \
#   --set controller.service.annotations."service\.beta\.kubernetes\.io/oci-load-balancer-shape"="flexible" \
#   --set controller.service.annotations."service\.beta\.kubernetes\.io/oci-load-balancer-shape-flex-min"="10" \
#   --set controller.service.annotations."service\.beta\.kubernetes\.io/oci-load-balancer-shape-flex-max"="100"

---
# ============================================================================
# Ingress for undateable.me
# ============================================================================
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: undateable-ingress
  namespace: undateable
  labels:
    app.kubernetes.io/name: undateable
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/proxy-body-size: "50m"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "300"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "300"
    # Enable for SSL/TLS
    # cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
  ingressClassName: nginx
  rules:
    # undateable.me
    - host: undateable.me
      http:
        paths:
          # API routes
          - path: /api/auth
            pathType: Prefix
            backend:
              service:
                name: auth-service
                port:
                  number: 8001
          - path: /api/profiles
            pathType: Prefix
            backend:
              service:
                name: profiles-service
                port:
                  number: 8002
          - path: /api/messages
            pathType: Prefix
            backend:
              service:
                name: messaging-service
                port:
                  number: 8003
          - path: /burn-api
            pathType: Prefix
            backend:
              service:
                name: burn-service
                port:
                  number: 8004
          - path: /ws
            pathType: Prefix
            backend:
              service:
                name: websocket-service
                port:
                  number: 8005
          # Default to frontend
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend-service
                port:
                  number: 80

    # www.undateable.me (same as above)
    - host: www.undateable.me
      http:
        paths:
          - path: /api/auth
            pathType: Prefix
            backend:
              service:
                name: auth-service
                port:
                  number: 8001
          - path: /api/profiles
            pathType: Prefix
            backend:
              service:
                name: profiles-service
                port:
                  number: 8002
          - path: /api/messages
            pathType: Prefix
            backend:
              service:
                name: messaging-service
                port:
                  number: 8003
          - path: /burn-api
            pathType: Prefix
            backend:
              service:
                name: burn-service
                port:
                  number: 8004
          - path: /ws
            pathType: Prefix
            backend:
              service:
                name: websocket-service
                port:
                  number: 8005
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend-service
                port:
                  number: 80
---
# ============================================================================
# Ingress for burnyourex.games
# ============================================================================
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: burnyourex-ingress
  namespace: undateable
  labels:
    app.kubernetes.io/name: burnyourex
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/proxy-body-size: "50m"
spec:
  ingressClassName: nginx
  rules:
    # burnyourex.games
    - host: burnyourex.games
      http:
        paths:
          # Burn API
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: burn-service
                port:
                  number: 8004
          # Default to burnyourex frontend
          - path: /
            pathType: Prefix
            backend:
              service:
                name: burnyourex-frontend
                port:
                  number: 80

    # www.burnyourex.games
    - host: www.burnyourex.games
      http:
        paths:
          - path: /api
            pathType: Prefix
            backend:
              service:
                name: burn-service
                port:
                  number: 8004
          - path: /
            pathType: Prefix
            backend:
              service:
                name: burnyourex-frontend
                port:
                  number: 80
---
# ============================================================================
# WebSocket-specific Ingress (with sticky sessions)
# ============================================================================
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: websocket-ingress
  namespace: undateable
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
    nginx.ingress.kubernetes.io/upstream-hash-by: "$remote_addr"
    nginx.ingress.kubernetes.io/affinity: "cookie"
    nginx.ingress.kubernetes.io/session-cookie-name: "ws-sticky"
    nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
    nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
    # WebSocket support (configuration-snippet removed for security)
    nginx.ingress.kubernetes.io/websocket-services: "websocket-service"
    nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
    nginx.ingress.kubernetes.io/proxy-set-headers: "ingress-nginx/custom-headers"
spec:
  ingressClassName: nginx
  rules:
    - host: undateable.me
      http:
        paths:
          - path: /socket.io
            pathType: Prefix
            backend:
              service:
                name: websocket-service
                port:
                  number: 8005
    - host: www.undateable.me
      http:
        paths:
          - path: /socket.io
            pathType: Prefix
            backend:
              service:
                name: websocket-service
                port:
                  number: 8005
