_format_version: "3.0"

# ============================================================
# Genex Kong API Gateway - Declarative Configuration
# Proxy on :8080, all frontend requests route through here
# ============================================================

services:
  # --- auth-service (NestJS :3010) ---
  - name: auth-service
    url: http://auth-service:3010
    routes:
      - name: auth-routes
        paths:
          - /api/v1/auth
        strip_path: false

  # --- user-service (NestJS :3001) ---
  - name: user-service
    url: http://user-service:3001
    routes:
      - name: user-routes
        paths:
          - /api/v1/users
        strip_path: false
      - name: wallet-routes
        paths:
          - /api/v1/wallet
        strip_path: false
      - name: message-routes
        paths:
          - /api/v1/messages
        strip_path: false
      - name: admin-user-routes
        paths:
          - /api/v1/admin/users
        strip_path: false
      - name: admin-dashboard-routes
        paths:
          - /api/v1/admin/dashboard
        strip_path: false
      - name: admin-system-routes
        paths:
          - /api/v1/admin/system
        strip_path: false

  # --- telemetry-service (NestJS :3011) ---
  - name: telemetry-service
    url: http://telemetry-service:3011
    routes:
      - name: telemetry-routes
        paths:
          - /api/v1/telemetry
        strip_path: false
      - name: admin-telemetry-routes
        paths:
          - /api/v1/admin/telemetry
        strip_path: false

  # --- admin-service (NestJS :3012) - App version management ---
  - name: admin-service
    url: http://admin-service:3012
    routes:
      - name: app-version-routes
        paths:
          - /api/v1/app/version
        strip_path: false
      - name: admin-version-routes
        paths:
          - /api/v1/admin/versions
        strip_path: false

  # --- referral-service (NestJS :3013) ---
  - name: referral-service
    url: http://referral-service:3013
    routes:
      - name: referral-routes
        paths:
          - /api/v1/referral
        strip_path: false

  # --- issuer-service (NestJS :3002) ---
  - name: issuer-service
    url: http://issuer-service:3002
    routes:
      - name: coupon-routes
        paths:
          - /api/v1/coupons
        strip_path: false
      - name: issuer-routes
        paths:
          - /api/v1/issuers
        strip_path: false
      - name: issuer-me-routes
        paths:
          - /api/v1/issuers/me
        strip_path: false
      - name: redemption-routes
        paths:
          - /api/v1/redemptions
        strip_path: false
      - name: coupon-batch-routes
        paths:
          - /api/v1/coupons/batch
        strip_path: false
      - name: admin-issuer-routes
        paths:
          - /api/v1/admin/issuers
        strip_path: false
      - name: admin-coupon-routes
        paths:
          - /api/v1/admin/coupons
        strip_path: false
      - name: admin-analytics-routes
        paths:
          - /api/v1/admin/analytics
        strip_path: false
      - name: admin-merchant-routes
        paths:
          - /api/v1/admin/merchant
        strip_path: false

  # --- trading-service (Go :3003) ---
  - name: trading-service
    url: http://trading-service:3003
    routes:
      - name: trade-routes
        paths:
          - /api/v1/trades
        strip_path: false
      - name: trades-my-routes
        paths:
          - /api/v1/trades/my
        strip_path: false
      - name: trades-coupon-transfer-routes
        paths:
          - /api/v1/trades/coupons
        strip_path: false
      - name: market-maker-routes
        paths:
          - /api/v1/mm
        strip_path: false
      - name: admin-trade-routes
        paths:
          - /api/v1/admin/trades
        strip_path: false
      - name: admin-mm-routes
        paths:
          - /api/v1/admin/mm
        strip_path: false

  # --- clearing-service (NestJS :3004) ---
  - name: clearing-service
    url: http://clearing-service:3004
    routes:
      - name: payment-routes
        paths:
          - /api/v1/payments
        strip_path: false
      - name: admin-finance-routes
        paths:
          - /api/v1/admin/finance
        strip_path: false
      - name: admin-reports-routes
        paths:
          - /api/v1/admin/reports
        strip_path: false

  # --- compliance-service (NestJS :3005) ---
  - name: compliance-service
    url: http://compliance-service:3005
    routes:
      - name: compliance-routes
        paths:
          - /api/v1/compliance
        strip_path: false
      - name: dispute-routes
        paths:
          - /api/v1/disputes
        strip_path: false
      - name: admin-risk-routes
        paths:
          - /api/v1/admin/risk
        strip_path: false
      - name: admin-compliance-routes
        paths:
          - /api/v1/admin/compliance
        strip_path: false
      - name: admin-dispute-routes
        paths:
          - /api/v1/admin/disputes
        strip_path: false
      - name: admin-insurance-routes
        paths:
          - /api/v1/admin/insurance
        strip_path: false

  # --- ai-service (NestJS :3006) - Anti-corruption layer to external AI agents ---
  - name: ai-service
    url: http://ai-service:3006
    routes:
      - name: ai-routes
        paths:
          - /api/v1/ai
        strip_path: false

  # --- notification-service (NestJS :3008) ---
  - name: notification-service
    url: http://notification-service:3008
    routes:
      - name: notification-routes
        paths:
          - /api/v1/notifications
        strip_path: false
      - name: announcement-routes
        paths:
          - /api/v1/announcements
        strip_path: false
      - name: device-token-routes
        paths:
          - /api/v1/device-tokens
        strip_path: false
      - name: admin-notification-routes
        paths:
          - /api/v1/admin/notifications
        strip_path: false
      - name: admin-announcement-routes
        paths:
          - /api/v1/admin/announcements
        strip_path: false
      - name: admin-user-tag-routes
        paths:
          - /api/v1/admin/user-tags
        strip_path: false

  # --- chain-indexer (Go :3009) ---
  - name: chain-indexer
    url: http://chain-indexer:3009
    routes:
      - name: chain-routes
        paths:
          - /api/v1/chain
        strip_path: false
      - name: admin-chain-routes
        paths:
          - /api/v1/admin/chain
        strip_path: false

  # --- translate-service (Go :3007) ---
  - name: translate-service
    url: http://translate-service:3007
    routes:
      - name: translate-routes
        paths:
          - /api/v1/translate
        strip_path: false

plugins:
  # CORS (allow all origins in development)
  - name: cors
    config:
      origins:
        - "*"
      methods:
        - GET
        - POST
        - PUT
        - PATCH
        - DELETE
        - OPTIONS
      headers:
        - Accept
        - Authorization
        - Content-Type
        - X-Requested-With
      exposed_headers:
        - X-Auth-Token
      credentials: true
      max_age: 3600

  # Global rate limiting (default: 100 req/min)
  - name: rate-limiting
    config:
      minute: 100
      policy: local
      fault_tolerant: true
      hide_client_headers: false
