services:
  # Modern development environment
  wordpress:
    image: wordpress:latest
    ports:
      - "8000:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DEBUG: 1
    volumes:
      - wordpress_data:/var/www/html
      - .:/var/www/html/wp-content/plugins/screenly-cast
    depends_on:
      db:
        condition: service_healthy

  db:
    image: mysql:8.0.32
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    command: >-
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_unicode_ci
    volumes:
      - db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 5s
      timeout: 5s
      retries: 10

  # Test environment with configurable PHP version
  wordpress-test:
    build:
      context: .
      dockerfile: tests/Dockerfile
      args:
        PHP_VERSION: ${PHP_VERSION:-7.4}  # Can be overridden with PHP_VERSION=8.1 docker compose up wordpress-test
    environment:
      - WP_TESTS_DIR=/tmp/wordpress-tests-lib
      - WP_CORE_DIR=/tmp/wordpress
      - WP_VERSION=${WP_VERSION:-6.4}  # Can be overridden with WP_VERSION=6.3 docker compose up wordpress-test
    volumes:
      - .:/var/www/html/wp-content/plugins/screenly-cast
    depends_on:
      db-test:
        condition: service_healthy

  db-test:
    image: mysql:8.0.32
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress_test
    command: >-
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_unicode_ci
    tmpfs:
      - /var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 5s
      timeout: 5s
      retries: 10

  # Linting environment
  lint:
    build:
      context: .
      dockerfile: tests/Dockerfile
      args:
        PHP_VERSION: ${PHP_VERSION:-7.4}
    volumes:
      - .:/var/www/html/wp-content/plugins/screenly-cast
    command: bash -c "composer update && composer run lint"

volumes:
  wordpress_data:
  db_data:
