# EN: Traefik Ingress for GoodGo Production - API Gateway routing
# VI: Traefik Ingress cho GoodGo Production - Dinh tuyen API Gateway
#
# Routes match infra/traefik/dynamic/routes.yml for consistency
# Host: api.goodgo.vn (API), pos.goodgo.vn (POS Frontend)

# =============================================================================
# API Ingress - Backend services
# =============================================================================
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: api-ingress
  namespace: production
  labels:
    environment: production
    platform: goodgo
  annotations:
    # EN: Traefik Ingress class
    # VI: Ingress class cua Traefik
    traefik.ingress.kubernetes.io/router.entrypoints: websecure
    traefik.ingress.kubernetes.io/router.tls: "true"
    # EN: Rate limiting and security middlewares
    # VI: Middleware gioi han toc do va bao mat
    traefik.ingress.kubernetes.io/router.middlewares: production-cors@kubernetescrd,production-secure-headers@kubernetescrd,production-rate-limit@kubernetescrd
    # EN: cert-manager TLS (production issuer)
    # VI: TLS bang cert-manager (issuer production)
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  ingressClassName: traefik
  tls:
  - hosts:
    - api.goodgo.vn
    secretName: api-production-tls
  rules:
  - host: api.goodgo.vn
    http:
      paths:
      # ===== IAM Service =====
      - path: /api/v1/auth
        pathType: Prefix
        backend:
          service:
            name: iam-service
            port:
              number: 8080
      - path: /api/v1/users
        pathType: Prefix
        backend:
          service:
            name: iam-service
            port:
              number: 8080
      - path: /api/v1/identity
        pathType: Prefix
        backend:
          service:
            name: iam-service
            port:
              number: 8080
      - path: /api/v1/access
        pathType: Prefix
        backend:
          service:
            name: iam-service
            port:
              number: 8080
      - path: /api/v1/governance
        pathType: Prefix
        backend:
          service:
            name: iam-service
            port:
              number: 8080
      - path: /api/v1/rbac
        pathType: Prefix
        backend:
          service:
            name: iam-service
            port:
              number: 8080
      - path: /api/v1/mfa
        pathType: Prefix
        backend:
          service:
            name: iam-service
            port:
              number: 8080
      - path: /api/v1/sessions
        pathType: Prefix
        backend:
          service:
            name: iam-service
            port:
              number: 8080
      # EN: IdentityServer OIDC endpoints
      # VI: IdentityServer OIDC endpoints
      - path: /connect
        pathType: Prefix
        backend:
          service:
            name: iam-service
            port:
              number: 8080
      - path: /.well-known
        pathType: Prefix
        backend:
          service:
            name: iam-service
            port:
              number: 8080

      # ===== Merchant Service =====
      - path: /api/v1/merchants
        pathType: Prefix
        backend:
          service:
            name: merchant-service
            port:
              number: 8080
      - path: /api/v1/shops
        pathType: Prefix
        backend:
          service:
            name: merchant-service
            port:
              number: 8080
      - path: /api/v1/subscriptions
        pathType: Prefix
        backend:
          service:
            name: merchant-service
            port:
              number: 8080

      # ===== Order Service =====
      - path: /api/v1/orders
        pathType: Prefix
        backend:
          service:
            name: order-service
            port:
              number: 8080
      # EN: POS/KDS SignalR Hub (WebSocket)
      # VI: POS/KDS SignalR Hub (WebSocket)
      - path: /hubs/pos
        pathType: Prefix
        backend:
          service:
            name: order-service
            port:
              number: 8080

      # ===== FnB Engine =====
      - path: /api/v1/kitchen
        pathType: Prefix
        backend:
          service:
            name: fnb-engine
            port:
              number: 8080
      - path: /api/v1/fnb
        pathType: Prefix
        backend:
          service:
            name: fnb-engine
            port:
              number: 8080
      - path: /api/v1/tables
        pathType: Prefix
        backend:
          service:
            name: fnb-engine
            port:
              number: 8080
      # EN: Kitchen Display SignalR Hub
      # VI: SignalR Hub Man hinh bep
      - path: /hubs/kitchen
        pathType: Prefix
        backend:
          service:
            name: fnb-engine
            port:
              number: 8080

      # ===== Inventory Service =====
      - path: /api/v1/inventory
        pathType: Prefix
        backend:
          service:
            name: inventory-service
            port:
              number: 8080
      - path: /api/v1/stock
        pathType: Prefix
        backend:
          service:
            name: inventory-service
            port:
              number: 8080

      # ===== Wallet Service =====
      - path: /api/v1/wallets
        pathType: Prefix
        backend:
          service:
            name: wallet-service
            port:
              number: 8080
      - path: /api/v1/points
        pathType: Prefix
        backend:
          service:
            name: wallet-service
            port:
              number: 8080
      - path: /api/v1/payments
        pathType: Prefix
        backend:
          service:
            name: wallet-service
            port:
              number: 8080

      # ===== Catalog Service =====
      - path: /api/v1/products
        pathType: Prefix
        backend:
          service:
            name: catalog-service
            port:
              number: 8080
      - path: /api/v1/categories
        pathType: Prefix
        backend:
          service:
            name: catalog-service
            port:
              number: 8080

      # ===== Booking Service =====
      - path: /api/v1/bookings
        pathType: Prefix
        backend:
          service:
            name: booking-service
            port:
              number: 8080
      - path: /api/v1/reservations
        pathType: Prefix
        backend:
          service:
            name: booking-service
            port:
              number: 8080

---
# =============================================================================
# POS Frontend Ingress
# =============================================================================
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: pos-web-ingress
  namespace: production
  labels:
    environment: production
    platform: goodgo
  annotations:
    traefik.ingress.kubernetes.io/router.entrypoints: websecure
    traefik.ingress.kubernetes.io/router.tls: "true"
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  ingressClassName: traefik
  tls:
  - hosts:
    - pos.goodgo.vn
    secretName: pos-production-tls
  rules:
  - host: pos.goodgo.vn
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: pos-web
            port:
              number: 8080
