version: '3.8'

services:
  postgres:
    image: postgres:14-alpine
    environment:
      POSTGRES_DB: mtgonline
      POSTGRES_USER: mtgonline_user
      POSTGRES_PASSWORD: mtgonline_password
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U mtgonline_user"]
      interval: 10s
      timeout: 10s
      retries: 5

  mtgdata:
    image: postgres:14-alpine
    environment:
      POSTGRES_DB: mtgdata
      POSTGRES_USER: mtgonline_user
      POSTGRES_PASSWORD: mtgonline_password
    ports:
      - "5433:5432"
    volumes:
      - mtgdata_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U mtgonline_user"]
      interval: 10s
      timeout: 10s
      retries: 5

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 10s
      retries: 5

  backend:
    image: mtgonline-backend:latest
    ports:
      - "5555:8000"
    environment:
      DATABASE_URL: "postgresql+asyncpg://mtgonline_user:mtgonline_password@postgres:5432/mtgonline"
      MTG_DATABASE_URL: "postgresql+asyncpg://mtgonline_user:mtgonline_password@mtgdata:5432/mtgdata"
      REDIS_URL: "redis://redis:6379"
    depends_on:
      postgres:
        condition: service_healthy
      mtgdata:
        condition: service_healthy
      redis:
        condition: service_healthy
    restart: unless-stopped

volumes:
  postgres_data:
  mtgdata_data:
  redis_data:
