# Dev overlay — load alongside docker-compose.yml:
#   docker compose -f docker-compose.yml -f docker-compose.dev.yml up
# (or `make dev`).
#
# Differences from prod:
#   * APP_ENV=development → Twig auto_reload kicks in (see View.php:36)
#   * Source dirs bind-mounted from host so edits show up without rebuild
#   * css-watcher sidecar runs `tailwindcss --watch` and seeds vendor JS
#   * tests profile builds the `tests` Dockerfile target on demand
#
# Volumes intentionally mount specific subdirs, NOT the project root —
# mounting `.` would mask the composer-installed /var/www/html/vendor.
services:
  app:
    environment:
      APP_ENV: development
    volumes:
      - ./src:/var/www/html/src
      - ./views:/var/www/html/views
      - ./public:/var/www/html/public
      - ./assets:/var/www/html/assets
      - ./migrations:/var/www/html/migrations
      - ./bin:/var/www/html/bin
      - ./tailwind.config.js:/var/www/html/tailwind.config.js
      - ./composer.json:/var/www/html/composer.json
      - ./composer.lock:/var/www/html/composer.lock
      - ./phpunit.xml:/var/www/html/phpunit.xml

  css-watcher:
    build:
      context: .
      target: css-watcher
    # Run as the host user so files written into the bind-mounted host dirs
    # (public/assets/css/app.css, public/assets/js/vendor/*) land with the
    # right ownership and don't need a `sudo chown` later. The Makefile
    # exports HOST_UID/HOST_GID; the :-1000 fallback covers the typical
    # case when someone invokes compose directly without going through make.
    user: "${HOST_UID:-1000}:${HOST_GID:-1000}"
    # Tailwind's `--watch` mode listens on stdin and exits on EOF so a parent
    # process closing the pipe terminates it cleanly. Under `compose up` stdin
    # is closed by default, which makes the watcher exit 0 immediately and
    # `restart: unless-stopped` then loops it. Keeping stdin open + a TTY
    # attached lets chokidar actually start.
    stdin_open: true
    tty: true
    volumes:
      - ./assets:/build/assets
      - ./views:/build/views
      - ./src:/build/src
      - ./public:/build/public
      - ./tailwind.config.js:/build/tailwind.config.js
    restart: unless-stopped

  tests:
    build:
      context: .
      target: tests
    profiles: ["test"]
    env_file: .env
    # Read-only bind mounts — tests should never mutate source. The data
    # volume is anonymous and per-run, so each `docker compose run --rm
    # tests` gets a fresh SQLite via the entrypoint's migrate step.
    volumes:
      - ./src:/var/www/html/src:ro
      - ./tests:/var/www/html/tests:ro
      - ./views:/var/www/html/views:ro
      - ./migrations:/var/www/html/migrations:ro
      - ./bin:/var/www/html/bin:ro
      - ./phpunit.xml:/var/www/html/phpunit.xml:ro
      - ./composer.json:/var/www/html/composer.json:ro
      - ./composer.lock:/var/www/html/composer.lock:ro
