# =============================================================================
# RWA Backend Services - Windows Local Development
# =============================================================================
# 用于在 Windows 上本地测试 auto-create-account 流程
#
# 包含服务:
#   - PostgreSQL (各服务独立数据库)
#   - Redis
#   - Kafka + Zookeeper
#   - mpc-system (Go TSS 后端)
#   - identity-service
#   - mpc-service
#   - blockchain-service
#   - backup-service
#
# 使用方法:
#   docker-compose -f docker-compose.windows.yml --env-file .env.windows up -d
#
# =============================================================================

services:
  # ============================================
  # Infrastructure - Database & Cache
  # ============================================

  postgres:
    image: postgres:15-alpine
    container_name: rwa-postgres
    environment:
      POSTGRES_USER: rwa_user
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-rwa_dev_password}
      POSTGRES_MULTIPLE_DATABASES: rwa_identity,rwa_mpc,rwa_blockchain,rwa_backup,rwa_referral,rwa_wallet,rwa_planting,rwa_reward,rwa_leaderboard,rwa_reporting,rwa_authorization,rwa_admin,mpc_system
    volumes:
      - postgres-data:/var/lib/postgresql/data
      - ./scripts/init-multiple-databases.sh:/docker-entrypoint-initdb.d/init-multiple-databases.sh:ro
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U rwa_user"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - rwa-network

  redis:
    image: redis:7-alpine
    container_name: rwa-redis
    ports:
      - "6379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - rwa-network

  # ============================================
  # Infrastructure - Kafka
  # ============================================

  zookeeper:
    image: confluentinc/cp-zookeeper:7.5.0
    container_name: rwa-zookeeper
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    ports:
      - "2181:2181"
    networks:
      - rwa-network

  kafka:
    image: confluentinc/cp-kafka:7.5.0
    container_name: rwa-kafka
    depends_on:
      - zookeeper
    ports:
      - "9092:9092"
      - "29092:29092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"
    healthcheck:
      test: ["CMD", "kafka-topics", "--bootstrap-server", "localhost:9092", "--list"]
      interval: 30s
      timeout: 10s
      retries: 5
    networks:
      - rwa-network

  # ============================================
  # MPC System (Go TSS Backend)
  # ============================================

  mpc-postgres:
    image: postgres:15-alpine
    container_name: mpc-postgres
    environment:
      POSTGRES_DB: mpc_system
      POSTGRES_USER: mpc_user
      POSTGRES_PASSWORD: ${MPC_POSTGRES_PASSWORD:-mpc_dev_password}
    volumes:
      - mpc-postgres-data:/var/lib/postgresql/data
      - ./mpc-system/migrations:/docker-entrypoint-initdb.d:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U mpc_user -d mpc_system"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - rwa-network

  mpc-session-coordinator:
    build:
      context: ./mpc-system
      dockerfile: services/session-coordinator/Dockerfile
    container_name: mpc-session-coordinator
    ports:
      - "8081:8080"
    environment:
      MPC_SERVER_GRPC_PORT: 50051
      MPC_SERVER_HTTP_PORT: 8080
      MPC_SERVER_ENVIRONMENT: development
      MPC_LOGGER_LEVEL: debug
      MPC_DATABASE_HOST: mpc-postgres
      MPC_DATABASE_PORT: 5432
      MPC_DATABASE_USER: mpc_user
      MPC_DATABASE_PASSWORD: ${MPC_POSTGRES_PASSWORD:-mpc_dev_password}
      MPC_DATABASE_DBNAME: mpc_system
      MPC_DATABASE_SSLMODE: disable
      SESSION_COORDINATOR_ADDR: mpc-session-coordinator:50051
      MPC_JWT_SECRET_KEY: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      MPC_JWT_ISSUER: mpc-system
      MESSAGE_ROUTER_ADDR: mpc-message-router:50051
      ACCOUNT_SERVICE_ADDR: http://mpc-account-service:8080
    depends_on:
      mpc-postgres:
        condition: service_healthy
      mpc-message-router:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - rwa-network

  mpc-message-router:
    build:
      context: ./mpc-system
      dockerfile: services/message-router/Dockerfile
    container_name: mpc-message-router
    ports:
      - "50051:50051"  # gRPC for party connections
      - "8082:8080"
    environment:
      MPC_SERVER_GRPC_PORT: 50051
      MPC_SERVER_HTTP_PORT: 8080
      MPC_SERVER_ENVIRONMENT: development
      MPC_LOGGER_LEVEL: debug
      MPC_DATABASE_HOST: mpc-postgres
      MPC_DATABASE_PORT: 5432
      MPC_DATABASE_USER: mpc_user
      MPC_DATABASE_PASSWORD: ${MPC_POSTGRES_PASSWORD:-mpc_dev_password}
      MPC_DATABASE_DBNAME: mpc_system
      MPC_DATABASE_SSLMODE: disable
      SESSION_COORDINATOR_ADDR: mpc-session-coordinator:50051
    depends_on:
      mpc-postgres:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - rwa-network

  mpc-server-party-1:
    build:
      context: ./mpc-system
      dockerfile: services/server-party/Dockerfile
    container_name: mpc-server-party-1
    environment:
      MPC_SERVER_GRPC_PORT: 50051
      MPC_SERVER_HTTP_PORT: 8080
      MPC_SERVER_ENVIRONMENT: development
      MPC_LOGGER_LEVEL: debug
      MPC_DATABASE_HOST: mpc-postgres
      MPC_DATABASE_PORT: 5432
      MPC_DATABASE_USER: mpc_user
      MPC_DATABASE_PASSWORD: ${MPC_POSTGRES_PASSWORD:-mpc_dev_password}
      MPC_DATABASE_DBNAME: mpc_system
      MPC_DATABASE_SSLMODE: disable
      MESSAGE_ROUTER_ADDR: mpc-message-router:50051
      MPC_CRYPTO_MASTER_KEY: ${CRYPTO_MASTER_KEY:-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef}
      PARTY_ID: server-party-1
    depends_on:
      mpc-postgres:
        condition: service_healthy
      mpc-session-coordinator:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - rwa-network

  mpc-server-party-2:
    build:
      context: ./mpc-system
      dockerfile: services/server-party/Dockerfile
    container_name: mpc-server-party-2
    environment:
      MPC_SERVER_GRPC_PORT: 50051
      MPC_SERVER_HTTP_PORT: 8080
      MPC_SERVER_ENVIRONMENT: development
      MPC_LOGGER_LEVEL: debug
      MPC_DATABASE_HOST: mpc-postgres
      MPC_DATABASE_PORT: 5432
      MPC_DATABASE_USER: mpc_user
      MPC_DATABASE_PASSWORD: ${MPC_POSTGRES_PASSWORD:-mpc_dev_password}
      MPC_DATABASE_DBNAME: mpc_system
      MPC_DATABASE_SSLMODE: disable
      MESSAGE_ROUTER_ADDR: mpc-message-router:50051
      MPC_CRYPTO_MASTER_KEY: ${CRYPTO_MASTER_KEY:-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef}
      PARTY_ID: server-party-2
    depends_on:
      mpc-postgres:
        condition: service_healthy
      mpc-session-coordinator:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - rwa-network

  mpc-server-party-3:
    build:
      context: ./mpc-system
      dockerfile: services/server-party/Dockerfile
    container_name: mpc-server-party-3
    environment:
      MPC_SERVER_GRPC_PORT: 50051
      MPC_SERVER_HTTP_PORT: 8080
      MPC_SERVER_ENVIRONMENT: development
      MPC_LOGGER_LEVEL: debug
      MPC_DATABASE_HOST: mpc-postgres
      MPC_DATABASE_PORT: 5432
      MPC_DATABASE_USER: mpc_user
      MPC_DATABASE_PASSWORD: ${MPC_POSTGRES_PASSWORD:-mpc_dev_password}
      MPC_DATABASE_DBNAME: mpc_system
      MPC_DATABASE_SSLMODE: disable
      MESSAGE_ROUTER_ADDR: mpc-message-router:50051
      MPC_CRYPTO_MASTER_KEY: ${CRYPTO_MASTER_KEY:-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef}
      PARTY_ID: server-party-3
    depends_on:
      mpc-postgres:
        condition: service_healthy
      mpc-session-coordinator:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - rwa-network

  mpc-server-party-api:
    build:
      context: ./mpc-system
      dockerfile: services/server-party-api/Dockerfile
    container_name: mpc-server-party-api
    ports:
      - "8083:8080"
    environment:
      MPC_SERVER_HTTP_PORT: 8080
      MPC_SERVER_ENVIRONMENT: development
      SESSION_COORDINATOR_ADDR: mpc-session-coordinator:50051
      MESSAGE_ROUTER_ADDR: mpc-message-router:50051
      MPC_CRYPTO_MASTER_KEY: ${CRYPTO_MASTER_KEY:-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef}
      MPC_API_KEY: ${MPC_API_KEY:-dev_mpc_api_key_for_testing}
      PARTY_ID: delegate-party
      PARTY_ROLE: delegate
    depends_on:
      mpc-session-coordinator:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - rwa-network

  mpc-account-service:
    build:
      context: ./mpc-system
      dockerfile: services/account/Dockerfile
    container_name: mpc-account-service
    ports:
      - "4000:8080"
    environment:
      MPC_SERVER_GRPC_PORT: 50051
      MPC_SERVER_HTTP_PORT: 8080
      MPC_SERVER_ENVIRONMENT: development
      MPC_LOGGER_LEVEL: debug
      MPC_DATABASE_HOST: mpc-postgres
      MPC_DATABASE_PORT: 5432
      MPC_DATABASE_USER: mpc_user
      MPC_DATABASE_PASSWORD: ${MPC_POSTGRES_PASSWORD:-mpc_dev_password}
      MPC_DATABASE_DBNAME: mpc_system
      MPC_DATABASE_SSLMODE: disable
      SESSION_COORDINATOR_ADDR: mpc-session-coordinator:50051
      MPC_COORDINATOR_URL: mpc-session-coordinator:50051
      MPC_JWT_SECRET_KEY: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      MPC_API_KEY: ${MPC_API_KEY:-dev_mpc_api_key_for_testing}
      ALLOWED_IPS: ""
    depends_on:
      mpc-postgres:
        condition: service_healthy
      mpc-session-coordinator:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - rwa-network

  # ============================================
  # NestJS Backend Services
  # ============================================

  identity-service:
    build:
      context: ./services/identity-service
      dockerfile: Dockerfile
    container_name: rwa-identity-service
    ports:
      - "3000:3000"
    environment:
      APP_PORT: 3000
      APP_ENV: development
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_identity?schema=public
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      JWT_ACCESS_EXPIRES_IN: 2h
      JWT_REFRESH_EXPIRES_IN: 30d
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 0
      KAFKA_BROKERS: kafka:29092
      KAFKA_CLIENT_ID: identity-service
      KAFKA_GROUP_ID: identity-service-group
      MPC_SERVICE_URL: http://mpc-service:3006
      MPC_MODE: remote
      MPC_USE_EVENT_DRIVEN: "true"
      BACKUP_SERVICE_URL: http://backup-service:3002
      BACKUP_SERVICE_ENABLED: "true"
      SERVICE_JWT_SECRET: ${SERVICE_JWT_SECRET:-dev_service_jwt_secret}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      kafka:
        condition: service_healthy
    networks:
      - rwa-network

  mpc-service:
    build:
      context: ./services/mpc-service
      dockerfile: Dockerfile
    container_name: rwa-mpc-service
    ports:
      - "3006:3006"
    environment:
      NODE_ENV: development
      APP_PORT: 3006
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_mpc?schema=public
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 5
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      KAFKA_BROKERS: kafka:29092
      KAFKA_CLIENT_ID: mpc-service
      KAFKA_GROUP_ID: mpc-service-group
      MPC_ACCOUNT_SERVICE_URL: http://mpc-account-service:8080
      MPC_COORDINATOR_URL: http://mpc-session-coordinator:8080
      MPC_SESSION_COORDINATOR_URL: http://mpc-session-coordinator:8080
      MPC_MESSAGE_ROUTER_WS_URL: ws://mpc-message-router:8080
      MPC_SERVER_PARTY_API_URL: http://mpc-server-party-api:8080
      MPC_JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      MPC_API_KEY: ${MPC_API_KEY:-dev_mpc_api_key_for_testing}
      BLOCKCHAIN_SERVICE_URL: http://blockchain-service:3012
      SHARE_MASTER_KEY: ${CRYPTO_MASTER_KEY:-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef}
      BACKUP_SERVICE_URL: http://backup-service:3002
      BACKUP_SERVICE_ENABLED: "true"
      SERVICE_JWT_SECRET: ${SERVICE_JWT_SECRET:-dev_service_jwt_secret}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      kafka:
        condition: service_healthy
      mpc-account-service:
        condition: service_healthy
      backup-service:
        condition: service_healthy
    networks:
      - rwa-network

  blockchain-service:
    build:
      context: ./services/blockchain-service
      dockerfile: Dockerfile
    container_name: rwa-blockchain-service
    ports:
      - "3012:3012"
    environment:
      NODE_ENV: development
      PORT: 3012
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_blockchain?schema=public
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 11
      KAFKA_BROKERS: kafka:29092
      KAFKA_CLIENT_ID: blockchain-service
      KAFKA_GROUP_ID: blockchain-service-group
      # 使用测试网
      NETWORK_MODE: testnet
      # KAVA Testnet 配置
      KAVA_RPC_URL: https://evm.testnet.kava.io
      KAVA_USDT_CONTRACT: "0xc12f6A4A7Fd0965085B044A67a39CcA2ff7fe0dF"
      # BSC Testnet 配置
      BSC_RPC_URL: https://data-seed-prebsc-1-s1.binance.org:8545
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      kafka:
        condition: service_healthy
    networks:
      - rwa-network

  backup-service:
    build:
      context: ./services/backup-service
      dockerfile: Dockerfile
    container_name: rwa-backup-service
    ports:
      - "3002:3002"
    environment:
      APP_PORT: 3002
      APP_ENV: development
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_backup?schema=public
      SERVICE_JWT_SECRET: ${SERVICE_JWT_SECRET:-dev_service_jwt_secret}
      ALLOWED_SERVICES: identity-service,recovery-service,mpc-service
      BACKUP_ENCRYPTION_KEY: ${BACKUP_ENCRYPTION_KEY:-0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef}
      BACKUP_ENCRYPTION_KEY_ID: key-v1
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - rwa-network

  referral-service:
    build:
      context: ./services/referral-service
      dockerfile: Dockerfile
    container_name: rwa-referral-service
    ports:
      - "3004:3004"
    environment:
      NODE_ENV: development
      APP_PORT: 3004
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_referral?schema=public
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 4
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      KAFKA_BROKERS: kafka:29092
      KAFKA_CLIENT_ID: referral-service
      KAFKA_GROUP_ID: referral-service-group
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      kafka:
        condition: service_healthy
    networks:
      - rwa-network

  wallet-service:
    build:
      context: ./services/wallet-service
      dockerfile: Dockerfile
    container_name: rwa-wallet-service
    ports:
      - "3001:3001"
    environment:
      NODE_ENV: development
      APP_PORT: 3001
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_wallet?schema=public
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 1
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      KAFKA_BROKERS: kafka:29092
      KAFKA_CLIENT_ID: wallet-service
      KAFKA_GROUP_ID: wallet-service-group
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      kafka:
        condition: service_healthy
    networks:
      - rwa-network

  planting-service:
    build:
      context: ./services/planting-service
      dockerfile: Dockerfile
    container_name: rwa-planting-service
    ports:
      - "3003:3003"
    environment:
      NODE_ENV: development
      APP_PORT: 3003
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_planting?schema=public
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 2
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      KAFKA_BROKERS: kafka:29092
      KAFKA_CLIENT_ID: planting-service
      KAFKA_GROUP_ID: planting-service-group
      WALLET_SERVICE_URL: http://wallet-service:3001
      IDENTITY_SERVICE_URL: http://identity-service:3000
      REFERRAL_SERVICE_URL: http://referral-service:3004
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      kafka:
        condition: service_healthy
    networks:
      - rwa-network

  reward-service:
    build:
      context: ./services/reward-service
      dockerfile: Dockerfile
    container_name: rwa-reward-service
    ports:
      - "3005:3005"
    environment:
      NODE_ENV: development
      APP_PORT: 3005
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_reward?schema=public
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 4
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      KAFKA_BROKERS: kafka:29092
      KAFKA_CLIENT_ID: reward-service
      KAFKA_GROUP_ID: reward-service-group
      REFERRAL_SERVICE_URL: http://referral-service:3004
      AUTHORIZATION_SERVICE_URL: http://authorization-service:3009
      WALLET_SERVICE_URL: http://wallet-service:3001
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      kafka:
        condition: service_healthy
    networks:
      - rwa-network

  leaderboard-service:
    build:
      context: ./services/leaderboard-service
      dockerfile: Dockerfile
    container_name: rwa-leaderboard-service
    ports:
      - "3007:3007"
    environment:
      NODE_ENV: development
      APP_PORT: 3007
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_leaderboard?schema=public
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 6
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      KAFKA_BROKERS: kafka:29092
      KAFKA_CLIENT_ID: leaderboard-service
      KAFKA_GROUP_ID: leaderboard-service-group
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      kafka:
        condition: service_healthy
    networks:
      - rwa-network

  reporting-service:
    build:
      context: ./services/reporting-service
      dockerfile: Dockerfile
    container_name: rwa-reporting-service
    ports:
      - "3008:3008"
    environment:
      NODE_ENV: development
      APP_PORT: 3008
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_reporting?schema=public
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 7
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      KAFKA_BROKERS: kafka:29092
      KAFKA_CLIENT_ID: reporting-service
      KAFKA_GROUP_ID: reporting-service-group
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      kafka:
        condition: service_healthy
    networks:
      - rwa-network

  authorization-service:
    build:
      context: ./services/authorization-service
      dockerfile: Dockerfile
    container_name: rwa-authorization-service
    ports:
      - "3009:3009"
    environment:
      NODE_ENV: development
      APP_PORT: 3009
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_authorization?schema=public
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 8
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
      KAFKA_BROKERS: kafka:29092
      KAFKA_CLIENT_ID: authorization-service
      KAFKA_GROUP_ID: authorization-service-group
      REFERRAL_SERVICE_URL: http://referral-service:3004
      REFERRAL_SERVICE_ENABLED: "true"
      IDENTITY_SERVICE_URL: http://identity-service:3000
      IDENTITY_SERVICE_ENABLED: "true"
      REWARD_SERVICE_URL: http://reward-service:3005
      REWARD_SERVICE_ENABLED: "true"
      # 注意：不添加 reward-service 依赖，避免循环依赖
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      kafka:
        condition: service_healthy
    networks:
      - rwa-network

  admin-service:
    build:
      context: ./services/admin-service
      dockerfile: Dockerfile
    container_name: rwa-admin-service
    ports:
      - "3010:3010"
    environment:
      NODE_ENV: development
      APP_PORT: 3010
      DATABASE_URL: postgresql://rwa_user:${POSTGRES_PASSWORD:-rwa_dev_password}@postgres:5432/rwa_admin?schema=public
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_DB: 9
      JWT_SECRET: ${JWT_SECRET:-dev_jwt_secret_key_min_32_chars_long}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - rwa-network

# ============================================
# Networks
# ============================================
networks:
  rwa-network:
    driver: bridge

# ============================================
# Volumes
# ============================================
volumes:
  postgres-data:
  mpc-postgres-data:
