version: '3.8'

services:
  mysql:
    image: mysql:8.0
    container_name: FurryPlace-mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpassword}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-FurryPlace}
      MYSQL_USER: ${MYSQL_USER:-FurryPlace}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-FurryPlacepassword}
    # No ports exposed - only accessible within Docker network
    volumes:
      - mysql-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD:-rootpassword}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - FurryPlace-network

  adminer:
    image: adminer:latest
    container_name: FurryPlace-adminer
    restart: unless-stopped
    ports:
      - "${ADMINER_PORT:-8080}:8080"
    environment:
      ADMINER_DEFAULT_SERVER: mysql
    depends_on:
      - mysql
    networks:
      - FurryPlace-network

  app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        USE_FRONTEND_BACKUP: ${USE_FRONTEND_BACKUP:-false}
    container_name: FurryPlace-app
    restart: unless-stopped
    ports:
      - "${PORT:-3000}:3000"
    environment:
      PORT: 3000
      DATABASE_URL: "mysql://${MYSQL_USER:-FurryPlace}:${MYSQL_PASSWORD:-FurryPlacepassword}@mysql:3306/${MYSQL_DATABASE:-FurryPlace}"
      JWT_SECRET: ${JWT_SECRET:-change-this-secret-in-production}
      NODE_ENV: production
      GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
      GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
      GOOGLE_CALLBACK_URL: ${GOOGLE_CALLBACK_URL:-http://localhost:3000/auth/google/callback}
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - FurryPlace-network
    command: >
      sh -c "
        echo 'Waiting for database to be ready...' &&
        sleep 5 &&
        echo 'Running database migrations...' &&
        pnpm db:push -- --accept-data-loss &&
        echo 'Starting application...' &&
        node dist/index.js
      "

volumes:
  mysql-data:

networks:
  FurryPlace-network:
    driver: bridge
