# Shadowed Realms Docker Compose Configuration
# File Location: D:\shadowed-realms-mobile\ShadowedRealmsMobile\src\server\docker-compose.yml
version: '3.8'

services:
  # ===============================
  # GAME API SERVER
  # ===============================
  shadowed-realms-api:
    build:
      context: ../../
      dockerfile: src/server/ShadowedRealms.API/Dockerfile
    image: shadowedrealms/api:latest
    container_name: sr-api
    restart: unless-stopped
    
    ports:
      - "8080:8080"    # API endpoints
      - "8443:8443"    # HTTPS (if configured)
    
    environment:
      # Database connection (replace with your PostgreSQL VM IP)
      - DATABASE_CONNECTION_STRING=Host=${POSTGRES_HOST};Database=${POSTGRES_DB};Username=${POSTGRES_USER};Password=${POSTGRES_PASSWORD}
      
      # Redis connection (replace with your Redis VM IP or use same as Postgres)
      - REDIS_CONNECTION_STRING=${REDIS_HOST}:${REDIS_PORT}
      
      # JWT Configuration (MUST be set for production)
      - JWT_SECRET_KEY=${JWT_SECRET_KEY}
      - JWT_ISSUER=${JWT_ISSUER:-ShadowedRealms.API}
      - JWT_AUDIENCE=${JWT_AUDIENCE:-ShadowedRealms.Players}
      
      # CORS Origins
      - ALLOWED_ORIGINS=${ALLOWED_ORIGINS:-https://yourdomain.com,https://admin.yourdomain.com}
      
      # Container identification
      - CONTAINER_ID=sr-api-main
      - KINGDOM_IDS=${KINGDOM_IDS:-1,2,3,4,5}
      
      # ASP.NET Core settings
      - ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT:-Production}
      - ASPNETCORE_URLS=http://+:8080
    
    volumes:
      # Persist logs outside container
      - api-logs:/app/logs
      
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s
    
    networks:
      - shadowed-realms-network

  # ===============================
  # LOAD BALANCER / REVERSE PROXY
  # ===============================
  nginx:
    image: nginx:alpine
    container_name: sr-proxy
    restart: unless-stopped
    
    ports:
      - "80:80"
      - "443:443"
    
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - ./ssl:/etc/nginx/ssl:ro  # SSL certificates (when ready)
      - nginx-logs:/var/log/nginx
      
    depends_on:
      - shadowed-realms-api
      
    networks:
      - shadowed-realms-network

  # ===============================
  # ADMIN DASHBOARD (Optional)
  # ===============================
  shadowed-realms-admin:
    build:
      context: .
      dockerfile: ShadowedRealms.Admin/Dockerfile  # Create this later
    image: shadowedrealms/admin:latest
    container_name: sr-admin
    restart: unless-stopped
    
    ports:
      - "3000:3000"
    
    environment:
      - DATABASE_CONNECTION_STRING=Host=${POSTGRES_HOST:-your-postgres-vm-ip};Database=${POSTGRES_DB:-ShadowedRealms};Username=${ADMIN_USER:-admin};Password=${ADMIN_PASSWORD}
      - API_BASE_URL=http://shadowed-realms-api:8080
      - ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT:-Production}
    
    volumes:
      - admin-logs:/app/logs
      
    depends_on:
      - shadowed-realms-api
      
    networks:
      - shadowed-realms-network
    
    profiles:
      - admin  # Only start when explicitly requested

# ===============================
# VOLUMES
# ===============================
volumes:
  api-logs:
    driver: local
  admin-logs:
    driver: local
  nginx-logs:
    driver: local

# ===============================
# NETWORKS
# ===============================
networks:
  shadowed-realms-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.0.0/16

# ===============================
# ENVIRONMENT VARIABLES REQUIRED
# ===============================
# Create a .env file in the same directory with these values:
#
# POSTGRES_HOST=your.postgres.vm.ip
# POSTGRES_DB=ShadowedRealms
# POSTGRES_USER=gameserver
# POSTGRES_PASSWORD=your_secure_password
#
# REDIS_HOST=your.redis.vm.ip
# REDIS_PORT=6379
#
# JWT_SECRET_KEY=your_super_secure_jwt_secret_minimum_32_characters_long
# JWT_ISSUER=ShadowedRealms.API
# JWT_AUDIENCE=ShadowedRealms.Players
#
# KINGDOM_IDS=1,2,3,4,5
# ALLOWED_ORIGINS=https://yourdomain.com,https://admin.yourdomain.com