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

# =============================================================================
# API Ingress - Backend services
# =============================================================================
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: api-ingress
  namespace: staging
  labels:
    environment: staging
    platform: goodgo
  annotations:
    # EN: Nginx Ingress class
    # VI: Ingress class cua Nginx
    nginx.ingress.kubernetes.io/proxy-body-size: "50m"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "60"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "60"
    # EN: cert-manager TLS (Let's Encrypt production)
    # VI: TLS bang cert-manager (Let's Encrypt production)
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - api.techbi.org
    secretName: api-techbi-tls
  rules:
  - host: api.techbi.org
    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
      - path: /api/v1/sessions
        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

      # ===== Storage Service =====
      - path: /api/v1/files
        pathType: Prefix
        backend:
          service:
            name: storage-service
            port:
              number: 8080
      - path: /api/v1/quota
        pathType: Prefix
        backend:
          service:
            name: storage-service
            port:
              number: 8080
      - path: /api/v1/uploads
        pathType: Prefix
        backend:
          service:
            name: storage-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
      - path: /api/v1/appointments
        pathType: Prefix
        backend:
          service:
            name: booking-service
            port:
              number: 8080
      - path: /api/v1/therapists
        pathType: Prefix
        backend:
          service:
            name: booking-service
            port:
              number: 8080

      # ===== Chat Service =====
      - path: /api/v1/chats
        pathType: Prefix
        backend:
          service:
            name: chat-service
            port:
              number: 8080
      - path: /api/v1/messages
        pathType: Prefix
        backend:
          service:
            name: chat-service
            port:
              number: 8080
      - path: /api/v1/conversations
        pathType: Prefix
        backend:
          service:
            name: chat-service
            port:
              number: 8080
      # EN: Chat SignalR Hub (WebSocket)
      # VI: Chat SignalR Hub (WebSocket)
      - path: /hubs/chat
        pathType: Prefix
        backend:
          service:
            name: chat-service
            port:
              number: 8080

      # ===== Social Service =====
      - path: /api/v1/social
        pathType: Prefix
        backend:
          service:
            name: social-service
            port:
              number: 8080
      - path: /api/v1/relationships
        pathType: Prefix
        backend:
          service:
            name: social-service
            port:
              number: 8080

      # ===== Promotion Service =====
      - path: /api/v1/promotions
        pathType: Prefix
        backend:
          service:
            name: promotion-service
            port:
              number: 8080
      - path: /api/v1/vouchers
        pathType: Prefix
        backend:
          service:
            name: promotion-service
            port:
              number: 8080

      # ===== Membership Service =====
      - path: /api/v1/members
        pathType: Prefix
        backend:
          service:
            name: membership-service
            port:
              number: 8080
      - path: /api/v1/levels
        pathType: Prefix
        backend:
          service:
            name: membership-service
            port:
              number: 8080

      # ===== Mining Service =====
      - path: /api/v1/mining
        pathType: Prefix
        backend:
          service:
            name: mining-service
            port:
              number: 8080
      - path: /api/v1/circles
        pathType: Prefix
        backend:
          service:
            name: mining-service
            port:
              number: 8080
      - path: /api/v1/referrals
        pathType: Prefix
        backend:
          service:
            name: mining-service
            port:
              number: 8080

      # ===== Mission Service =====
      - path: /api/v1/missions
        pathType: Prefix
        backend:
          service:
            name: mission-service
            port:
              number: 8080
      - path: /api/v1/checkins
        pathType: Prefix
        backend:
          service:
            name: mission-service
            port:
              number: 8080

      # ===== Ads Manager Service =====
      - path: /api/v1/ads
        pathType: Prefix
        backend:
          service:
            name: ads-manager-service
            port:
              number: 8080
      - path: /api/v1/campaigns
        pathType: Prefix
        backend:
          service:
            name: ads-manager-service
            port:
              number: 8080
      - path: /api/v1/adsets
        pathType: Prefix
        backend:
          service:
            name: ads-manager-service
            port:
              number: 8080
      - path: /api/v1/audiences
        pathType: Prefix
        backend:
          service:
            name: ads-manager-service
            port:
              number: 8080

      # ===== Ads Serving Service =====
      - path: /api/v1/ads-serving
        pathType: Prefix
        backend:
          service:
            name: ads-serving-service
            port:
              number: 8080

      # ===== Ads Billing Service =====
      - path: /api/v1/ads-billing
        pathType: Prefix
        backend:
          service:
            name: ads-billing-service
            port:
              number: 8080
      - path: /api/v1/ad-invoices
        pathType: Prefix
        backend:
          service:
            name: ads-billing-service
            port:
              number: 8080

      # ===== Ads Tracking Service =====
      - path: /api/v1/ad-events
        pathType: Prefix
        backend:
          service:
            name: ads-tracking-service
            port:
              number: 8080
      - path: /api/v1/pixels
        pathType: Prefix
        backend:
          service:
            name: ads-tracking-service
            port:
              number: 8080
      - path: /api/v1/conversions
        pathType: Prefix
        backend:
          service:
            name: ads-tracking-service
            port:
              number: 8080

      # ===== Ads Analytics Service =====
      - path: /api/v1/ad-analytics
        pathType: Prefix
        backend:
          service:
            name: ads-analytics-service
            port:
              number: 8080
      - path: /api/v1/ad-reports
        pathType: Prefix
        backend:
          service:
            name: ads-analytics-service
            port:
              number: 8080

      # ===== Marketing Services =====
      - path: /api/v1/mkt/facebook
        pathType: Prefix
        backend:
          service:
            name: mkt-facebook-service
            port:
              number: 8080
      - path: /api/v1/mkt/whatsapp
        pathType: Prefix
        backend:
          service:
            name: mkt-whatsapp-service
            port:
              number: 8080
      - path: /api/v1/mkt/x
        pathType: Prefix
        backend:
          service:
            name: mkt-x-service
            port:
              number: 8080
      - path: /api/v1/mkt/zalo
        pathType: Prefix
        backend:
          service:
            name: mkt-zalo-service
            port:
              number: 8080

---
# =============================================================================
# POS Frontend Ingress
# =============================================================================
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: pos-web-ingress
  namespace: staging
  labels:
    environment: staging
    platform: goodgo
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "50m"
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - platform.techbi.org
    secretName: platform-techbi-tls
  rules:
  - host: platform.techbi.org
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: pos-web
            port:
              number: 8080
