# =============================================================================
# Kong API Gateway - �Mn
# =============================================================================
# (��:
#   1. /� Kong: docker compose up -d kong kong-db
#   2. Mnꨠ}
#
# �c: https://docs.konghq.com/gateway/latest/
# =============================================================================

_format_version: "3.0"
_transform: true

# =============================================================================
# Services - �
��I
# =============================================================================
services:
  # ---------------------------------------------------------------------------
  # Identity Service - ����
�
  # ---------------------------------------------------------------------------
  - name: identity-service
    url: http://identity-service:3000
    routes:
      - name: identity-auth
        paths:
          - /api/v1/auth
        strip_path: false
      - name: identity-users
        paths:
          - /api/v1/users
        strip_path: false
      - name: identity-health
        paths:
          - /api/v1/identity/health
        strip_path: true

  # ---------------------------------------------------------------------------
  # Wallet Service - �
�
  # ---------------------------------------------------------------------------
  - name: wallet-service
    url: http://wallet-service:3001
    routes:
      - name: wallet-api
        paths:
          - /api/v1/wallets
        strip_path: false
      - name: wallet-health
        paths:
          - /api/v1/wallet/health
        strip_path: true

  # ---------------------------------------------------------------------------
  # Backup Service - �
�
  # ---------------------------------------------------------------------------
  - name: backup-service
    url: http://backup-service:3002
    routes:
      - name: backup-api
        paths:
          - /api/v1/backups
        strip_path: false

  # ---------------------------------------------------------------------------
  # Planting Service - �

�
  # ---------------------------------------------------------------------------
  - name: planting-service
    url: http://planting-service:3003
    routes:
      - name: planting-api
        paths:
          - /api/v1/plantings
          - /api/v1/trees
        strip_path: false

  # ---------------------------------------------------------------------------
  # Referral Service - �P
�
  # ---------------------------------------------------------------------------
  - name: referral-service
    url: http://referral-service:3004
    routes:
      - name: referral-api
        paths:
          - /api/v1/referrals
        strip_path: false

  # ---------------------------------------------------------------------------
  # Reward Service - V�
�
  # ---------------------------------------------------------------------------
  - name: reward-service
    url: http://reward-service:3005
    routes:
      - name: reward-api
        paths:
          - /api/v1/rewards
        strip_path: false

  # ---------------------------------------------------------------------------
  # MPC Service - ���
�
  # ---------------------------------------------------------------------------
  - name: mpc-service
    url: http://mpc-service:3006
    routes:
      - name: mpc-api
        paths:
          - /api/v1/mpc
        strip_path: false

  # ---------------------------------------------------------------------------
  # Leaderboard Service - �L�
�
  # ---------------------------------------------------------------------------
  - name: leaderboard-service
    url: http://leaderboard-service:3007
    routes:
      - name: leaderboard-api
        paths:
          - /api/v1/leaderboard
        strip_path: false

  # ---------------------------------------------------------------------------
  # Reporting Service - �h
�
  # ---------------------------------------------------------------------------
  - name: reporting-service
    url: http://reporting-service:3008
    routes:
      - name: reporting-api
        paths:
          - /api/v1/reports
          - /api/v1/statistics
        strip_path: false

  # ---------------------------------------------------------------------------
  # Authorization Service - �C
�
  # ---------------------------------------------------------------------------
  - name: authorization-service
    url: http://authorization-service:3009
    routes:
      - name: authorization-api
        paths:
          - /api/v1/authorization
          - /api/v1/permissions
          - /api/v1/roles
        strip_path: false

  # ---------------------------------------------------------------------------
  # Admin Service - �
� (+H,�)
  # ---------------------------------------------------------------------------
  - name: admin-service
    url: http://admin-service:3010
    routes:
      - name: admin-versions
        paths:
          - /api/v1/versions
        strip_path: false
      - name: admin-api
        paths:
          - /api/v1/admin
        strip_path: false

  # ---------------------------------------------------------------------------
  # Presence Service - (��
�
  # ---------------------------------------------------------------------------
  - name: presence-service
    url: http://presence-service:3011
    routes:
      - name: presence-api
        paths:
          - /api/v1/presence
        strip_path: false

# =============================================================================
# Plugins - h@��Mn
# =============================================================================
plugins:
  # CORS ��Mn
  - name: cors
    config:
      origins:
        - "https://rwaadmin.szaiai.com"
        - "https://update.szaiai.com"
        - "https://app.rwadurian.com"
        - "http://localhost:3000"
        - "http://localhost:3020"
      methods:
        - GET
        - POST
        - PUT
        - PATCH
        - DELETE
        - OPTIONS
      headers:
        - Accept
        - Accept-Version
        - Content-Length
        - Content-MD5
        - Content-Type
        - Date
        - Authorization
        - X-Auth-Token
      exposed_headers:
        - X-Auth-Token
      credentials: true
      max_age: 3600

  # �BPA
  - name: rate-limiting
    config:
      minute: 100
      hour: 5000
      policy: local

  # �B��
  - name: file-log
    config:
      path: /tmp/kong-access.log
      reopen: true

  # �B/͔'P6
  - name: request-size-limiting
    config:
      allowed_payload_size: 50
      size_unit: megabytes
