services:
  mysql:
    image: mysql:8.0
    ports:
      - "3306:3306"
    command: ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-root}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-mcbdl}
      MYSQL_USER: ${MYSQL_USER:-mcbdl}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-mcbdlpass}
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h localhost -p$$MYSQL_ROOT_PASSWORD"]
      interval: 5s
      timeout: 3s
      retries: 20

  backend:
    build:
      context: ./backend
    ports:
      - "4010:4010"
    environment:
      PORT: "4010"
      CORS_ORIGIN: ${CORS_ORIGIN:-http://localhost:5174}
      DB_HOST: mysql
      DB_PORT: "3306"
      DB_USER: ${MYSQL_USER:-mcbdl}
      DB_PASS: ${MYSQL_PASSWORD:-mcbdlpass}
      DB_NAME: ${MYSQL_DATABASE:-mcbdl}
      DB_CONNECT_RETRIES: "30"
      DB_CONNECT_RETRY_DELAY_MS: "1000"
      DB_DISABLE_SEED: ${DB_DISABLE_SEED:-1}
    volumes:
      - ./backend/data:/app/data
    depends_on:
      mysql:
        condition: service_healthy

  frontend:
    build:
      context: ./frontend
    ports:
      - "5174:5173"
    environment:
      VITE_PROXY_TARGET: http://backend:4010
      CHOKIDAR_USEPOLLING: "true"
    depends_on:
      - backend

  phpmyadmin:
    image: phpmyadmin:5-apache
    ports:
      - "8080:80"
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
      PMA_ARBITRARY: 1
    depends_on:
      mysql:
        condition: service_healthy

volumes:
  mysql_data:
