version: '3.8'

services:
  # -------------------------------------------------------------------------
  # Service Base de données
  # -------------------------------------------------------------------------
  database:
    image: postgres:15-alpine
    container_name: tax_database
    environment:
      POSTGRES_DB: app
      POSTGRES_PASSWORD: root
      POSTGRES_USER: app
    volumes:
      - db-data:/var/lib/postgresql/data
    ports:
      - "5433:5432"

  # -------------------------------------------------------------------------
  # Service Backend API (Symfony)
  # -------------------------------------------------------------------------
  php:
    build:
      context: ./api
      target: app_php_dev
    container_name: tax_api
    depends_on:
      - database
    restart: unless-stopped
    volumes:
      - ./api:/app
      - ./resources:/app/resources
    environment:
      # On simplifie les variables d'environnement
      DATABASE_URL: postgresql://app:root@database:5432/app?serverVersion=15&charset=utf8
      CORS_ALLOW_ORIGIN: ^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
      APP_SECRET: root
      XDEBUG_MODE: off
    # 👇 AJOUTE CETTE LIGNE POUR FORCER LE SERVEUR PHP SIMPLE
    command: php -S 0.0.0.0:80 -t public
    ports:
      - "8000:80"

  # -------------------------------------------------------------------------
  # Service Frontend (PWA)
  # -------------------------------------------------------------------------
  pwa:
    build:
      context: ./pwa
      target: dev
    container_name: tax_pwa
    volumes:
      - ./pwa:/app
      - /app/node_modules
    ports:
      - "3000:3000"
    environment:
      NEXT_PUBLIC_ENTRYPOINT: http://localhost:8000/api
      REACT_APP_API_URL: http://localhost:8000/api

volumes:
  db-data: