services:
  app:
    build: .
    ports:
      - "8080:80"
    environment:
      APP_ENV: local
      APP_DEBUG: "true"
      DB_HOST: db
      DB_PORT: 3306
      DB_DATABASE: volley_tournaments
      DB_USERNAME: volley
      DB_PASSWORD: volley
      JWT_SECRET: "dev-secret-change-me"
    volumes:
      - .:/var/www/html
    depends_on:
      db:
        condition: service_healthy

  websocket:
    build: .
    command: php /var/www/html/bin/websocket-server.php
    ports:
      - "8081:8081"
    environment:
      DB_HOST: db
      DB_PORT: 3306
      DB_DATABASE: volley_tournaments
      DB_USERNAME: volley
      DB_PASSWORD: volley
    volumes:
      - .:/var/www/html
    depends_on:
      db:
        condition: service_healthy

  db:
    image: mysql:8.4
    ports:
      - "3307:3306"
    environment:
      MYSQL_DATABASE: volley_tournaments
      MYSQL_USER: volley
      MYSQL_PASSWORD: volley
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - db_data:/var/lib/mysql
      - ./database/schema.sql:/docker-entrypoint-initdb.d/01-schema.sql:ro
      - ./database/seeds.sql:/docker-entrypoint-initdb.d/02-seeds.sql:ro
      - ./database/migrations/20260519_scoresheet_advanced.sql:/docker-entrypoint-initdb.d/03-scoresheet-advanced.sql:ro
      - ./database/migrations/20260519_ltv26_template_fields.sql:/docker-entrypoint-initdb.d/04-ltv26-template-fields.sql:ro
      - ./database/migrations/20260519_sheet_templates.sql:/docker-entrypoint-initdb.d/05-sheet-templates.sql:ro
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-proot"]
      interval: 5s
      timeout: 5s
      retries: 20

volumes:
  db_data:
