services:
  postgres:
    image: postgres:13
    container_name: wingsemu-postgres
    restart: unless-stopped
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB:-game}
      POSTGRES_USER: ${POSTGRES_USER:-postgres}
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
      interval: 10s
      timeout: 5s
      retries: 10

  redis:
    image: redis:7-alpine
    container_name: wingsemu-redis
    restart: unless-stopped
    command: ["redis-server", "--notify-keyspace-events", "Kx", "--appendonly", "yes"]
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 10

  mongodb:
    image: mongo:6
    container_name: wingsemu-mongodb
    restart: unless-stopped
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD}
    ports:
      - "27017:27017"
    volumes:
      - mongodb_data:/data/db
    healthcheck:
      test: ["CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ ping: 1 }).ok"]
      interval: 15s
      timeout: 10s
      retries: 10

  mqtt:
    image: emqx/emqx:latest
    container_name: wingsemu-mqtt
    restart: unless-stopped
    ports:
      - "1883:1883"
      - "18083:18083"
    healthcheck:
      test: ["CMD-SHELL", "emqx ctl status | grep -q 'is started'"]
      interval: 15s
      timeout: 10s
      retries: 10

  master:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: master
    container_name: wingsemu-master
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      mongodb:
        condition: service_healthy
      mqtt:
        condition: service_healthy
    environment:
      MASTER_PORT: 20500
      DATABASE_IP: postgres
      DATABASE_PORT: 5432
      DATABASE_NAME: ${POSTGRES_DB:-game}
      DATABASE_USER: ${POSTGRES_USER:-postgres}
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      REDIS_IP: redis
      REDIS_PORT: 6379
      POSTGRES_DATABASE_IP: postgres
      POSTGRES_DATABASE_PORT: 5432
      POSTGRES_DATABASE_NAME: ${POSTGRES_DB:-game}
      POSTGRES_DATABASE_USERNAME: ${POSTGRES_USER:-postgres}
      POSTGRES_DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      WINGSEMU_MONGO_HOST: mongodb
      WINGSEMU_MONGO_PORT: 27017
      WINGSEMU_MONGO_DB: wingsemu_logs
      WINGSEMU_MONGO_USERNAME: ${MONGO_ROOT_USERNAME}
      WINGSEMU_MONGO_PWD: ${MONGO_ROOT_PASSWORD}
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
    command: ["/app/Master.dll"]
    ports:
      - "20500:20500"

  login:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: login-server
    container_name: wingsemu-login
    restart: unless-stopped
    depends_on:
      master:
        condition: service_started
    environment:
      SERVER_PORT: 4004
      MASTER_IP: master
      MASTER_PORT: 20500
      REDIS_IP: redis
      REDIS_PORT: 6379
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
    command: ["/app/LoginServer.dll"]
    ports:
      - "4004:4004"

  gamechannel:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: game-server
    container_name: wingsemu-gamechannel
    restart: unless-stopped
    depends_on:
      master:
        condition: service_started
      database:
        condition: service_started
      bazaar:
        condition: service_started
      family:
        condition: service_started
      relation:
        condition: service_started
      mail:
        condition: service_started
      translation:
        condition: service_started
    environment:
      MASTER_IP: master
      MASTER_PORT: 20500
      DATABASE_IP: postgres
      DATABASE_PORT: 5432
      DATABASE_NAME: ${POSTGRES_DB:-game}
      DATABASE_USER: ${POSTGRES_USER:-postgres}
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      DB_SERVER_IP: database
      DB_SERVER_PORT: 29999
      BAZAAR_SERVER_IP: bazaar
      BAZAAR_SERVER_PORT: 25555
      FAMILY_SERVER_IP: family
      FAMILY_SERVER_PORT: 26666
      RELATION_SERVER_IP: relation
      RELATION_SERVER_PORT: 21111
      MAIL_SERVER_IP: mail
      MAIL_SERVER_PORT: 27777
      TRANSLATIONS_SERVER_IP: translation
      TRANSLATIONS_SERVER_PORT: 19999
      GAME_SERVER_IP: 0.0.0.0
      GAME_SERVER_PORT: 8000
      GAME_SERVER_CHANNEL_ID: 1
      GAME_SERVER_GROUP: 1
      HTTP_LISTEN_PORT: 17500
      REDIS_IP: redis
      REDIS_PORT: 6379
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
      WINGSEMU_MONGO_HOST: mongodb
      WINGSEMU_MONGO_PORT: 27017
      WINGSEMU_MONGO_DB: wingsemu_logs
      WINGSEMU_MONGO_USERNAME: ${MONGO_ROOT_USERNAME}
      WINGSEMU_MONGO_PWD: ${MONGO_ROOT_PASSWORD}
    command: ["/app/GameChannel.dll"]
    volumes:
      - ./resources:/app/resources:ro
      - ./config:/app/config
    ports:
      - "8000:8000"
      - "17500:17500"

  database:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: database-server
    container_name: wingsemu-database
    restart: unless-stopped
    depends_on:
      master:
        condition: service_started
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      mqtt:
        condition: service_healthy
    environment:
      DATABASE_SERVER_PORT: 29999
      MASTER_IP: master
      MASTER_PORT: 20500
      DATABASE_IP: postgres
      DATABASE_PORT: 5432
      DATABASE_NAME: ${POSTGRES_DB:-game}
      DATABASE_USER: ${POSTGRES_USER:-postgres}
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DATABASE_IP: postgres
      POSTGRES_DATABASE_PORT: 5432
      POSTGRES_DATABASE_NAME: ${POSTGRES_DB:-game}
      POSTGRES_DATABASE_USERNAME: ${POSTGRES_USER:-postgres}
      POSTGRES_DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      REDIS_IP: redis
      REDIS_PORT: 6379
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
    command: ["/app/DatabaseServer.dll"]
    ports:
      - "29999:29999"

  bazaar:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: bazaar-server
    container_name: wingsemu-bazaar
    restart: unless-stopped
    depends_on:
      master:
        condition: service_started
      database:
        condition: service_started
      redis:
        condition: service_healthy
      mqtt:
        condition: service_healthy
    environment:
      BAZAAR_SERVER_PORT: 25555
      MASTER_IP: master
      MASTER_PORT: 20500
      DATABASE_IP: postgres
      DATABASE_PORT: 5432
      DATABASE_NAME: ${POSTGRES_DB:-game}
      DATABASE_USER: ${POSTGRES_USER:-postgres}
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      DB_SERVER_IP: database
      DB_SERVER_PORT: 29999
      REDIS_IP: redis
      REDIS_PORT: 6379
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
    command: ["/app/BazaarServer.dll"]
    volumes:
      - ./resources:/app/resources:ro
      - ./config:/app/config
    ports:
      - "25555:25555"

  family:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: family-server
    container_name: wingsemu-family
    restart: unless-stopped
    depends_on:
      master:
        condition: service_started
      database:
        condition: service_started
      redis:
        condition: service_healthy
      mqtt:
        condition: service_healthy
    environment:
      FAMILY_SERVER_PORT: 26666
      MASTER_IP: master
      MASTER_PORT: 20500
      DATABASE_IP: postgres
      DATABASE_PORT: 5432
      DATABASE_NAME: ${POSTGRES_DB:-game}
      DATABASE_USER: ${POSTGRES_USER:-postgres}
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      DB_SERVER_IP: database
      DB_SERVER_PORT: 29999
      REDIS_IP: redis
      REDIS_PORT: 6379
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
    command: ["/app/FamilyServer.dll"]
    volumes:
      - ./resources:/app/resources:ro
      - ./config:/app/config
    ports:
      - "26666:26666"

  relation:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: relation-server
    container_name: wingsemu-relation
    restart: unless-stopped
    depends_on:
      master:
        condition: service_started
      database:
        condition: service_started
      redis:
        condition: service_healthy
      mqtt:
        condition: service_healthy
    environment:
      RELATION_SERVER_PORT: 21111
      MASTER_IP: master
      MASTER_PORT: 20500
      DATABASE_IP: postgres
      DATABASE_PORT: 5432
      DATABASE_NAME: ${POSTGRES_DB:-game}
      DATABASE_USER: ${POSTGRES_USER:-postgres}
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      DB_SERVER_IP: database
      DB_SERVER_PORT: 29999
      REDIS_IP: redis
      REDIS_PORT: 6379
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
    command: ["/app/RelationServer.dll"]
    volumes:
      - ./resources:/app/resources:ro
      - ./config:/app/config
    ports:
      - "21111:21111"

  mail:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: mail-server
    container_name: wingsemu-mail
    restart: unless-stopped
    depends_on:
      master:
        condition: service_started
      database:
        condition: service_started
      redis:
        condition: service_healthy
      mqtt:
        condition: service_healthy
    environment:
      MAIL_SERVER_PORT: 27777
      MASTER_IP: master
      MASTER_PORT: 20500
      DATABASE_IP: postgres
      DATABASE_PORT: 5432
      DATABASE_NAME: ${POSTGRES_DB:-game}
      DATABASE_USER: ${POSTGRES_USER:-postgres}
      DATABASE_PASSWORD: ${POSTGRES_PASSWORD}
      DB_SERVER_IP: database
      DB_SERVER_PORT: 29999
      REDIS_IP: redis
      REDIS_PORT: 6379
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
    command: ["/app/MailServer.dll"]
    volumes:
      - ./resources:/app/resources:ro
      - ./config:/app/config
    ports:
      - "27777:27777"

  translation:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: translation-server
    container_name: wingsemu-translation
    restart: unless-stopped
    depends_on:
      master:
        condition: service_started
      redis:
        condition: service_healthy
      mqtt:
        condition: service_healthy
    environment:
      TRANSLATION_SERVER_PORT: 19999
      MASTER_IP: master
      MASTER_PORT: 20500
      REDIS_IP: redis
      REDIS_PORT: 6379
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
    command: ["/app/TranslationsServer.dll"]
    volumes:
      - ./translations:/app/translations:ro
    ports:
      - "19999:19999"

  logs:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: logs-server
    container_name: wingsemu-logs
    restart: unless-stopped
    depends_on:
      master:
        condition: service_started
      mongodb:
        condition: service_healthy
      redis:
        condition: service_healthy
      mqtt:
        condition: service_healthy
    environment:
      LOGS_SERVER_PORT: 28888
      MASTER_IP: master
      MASTER_PORT: 20500
      REDIS_IP: redis
      REDIS_PORT: 6379
      WINGSEMU_MONGO_HOST: mongodb
      WINGSEMU_MONGO_PORT: 27017
      WINGSEMU_MONGO_DB: wingsemu_logs
      WINGSEMU_MONGO_USERNAME: ${MONGO_ROOT_USERNAME}
      WINGSEMU_MONGO_PWD: ${MONGO_ROOT_PASSWORD}
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
    command: ["/app/LogsServer.dll"]
    ports:
      - "28888:28888"

  scheduler:
    build:
      context: .
      dockerfile: docker/Dockerfile.service
      args:
        SERVICE_DIR: scheduler
    container_name: wingsemu-scheduler
    restart: unless-stopped
    depends_on:
      master:
        condition: service_started
      redis:
        condition: service_healthy
      mqtt:
        condition: service_healthy
    environment:
      MASTER_IP: master
      MASTER_PORT: 20500
      REDIS_IP: redis
      REDIS_PORT: 6379
      MQTT_BROKER_ADDRESS: mqtt
      MQTT_BROKER_PORT: 1883
    command: ["/app/Scheduler.dll"]
    ports:
      - "25000:25000"

volumes:
  postgres_data:
  redis_data:
  mongodb_data:



