services:
  # Base de données MySQL
  mysql:
    image: mysql:8.0
    container_name: lintello_mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: lintello
      MYSQL_USER: lintello
      MYSQL_PASSWORD: lintello_password
    volumes:
      - mysql_data:/var/lib/mysql
      - ./docker/mysql/conf.d:/etc/mysql/conf.d
    ports:
      - "3307:3306"  # Port 3307 pour cohabiter avec WAMP (port 3306)
    networks:
      - lintello_network
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-proot"]
      interval: 10s
      timeout: 5s
      retries: 5

  # PHP-FPM avec Symfony
  php:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: lintello_php
    restart: unless-stopped
    volumes:
      - ./:/var/www/lintello
      - ./docker/php/conf.d/custom.ini:/usr/local/etc/php/conf.d/custom.ini
    # tmpfs pour le cache Symfony - résout les problèmes de cache WSL2/Docker
    tmpfs:
      - /var/www/lintello/var/cache:mode=1777
      - /var/www/lintello/var/log:mode=1777
    networks:
      - lintello_network
    depends_on:
      mysql:
        condition: service_healthy
    environment:
      APP_ENV: dev
      DATABASE_URL: mysql://lintello:lintello_password@mysql:3306/lintello?serverVersion=8.0.32&charset=utf8mb4

  # Nginx
  nginx:
    image: nginx:alpine
    container_name: lintello_nginx
    restart: unless-stopped
    ports:
      - "8080:80"  # Port 8080 pour cohabiter avec WAMP (port 80)
      - "8443:443"  # Port 8443 pour HTTPS
    volumes:
      - ./:/var/www/lintello
      - ./docker/nginx/conf.d:/etc/nginx/conf.d
      - ./docker/nginx/logs:/var/log/nginx
    networks:
      - lintello_network
    depends_on:
      - php

  # phpMyAdmin
  phpmyadmin:
    image: phpmyadmin:latest
    container_name: lintello_phpmyadmin
    restart: unless-stopped
    ports:
      - "8082:80"
    environment:
      PMA_HOST: mysql
      PMA_USER: lintello
      PMA_PASSWORD: lintello_password
      MYSQL_ROOT_PASSWORD: root
    networks:
      - lintello_network
    depends_on:
      - mysql

  # Node.js pour le build frontend (optionnel, pour le développement)
  node:
    image: node:20-alpine
    container_name: lintello_node
    working_dir: /var/www/lintello/frontend
    volumes:
      - ./frontend:/var/www/lintello/frontend
      - ./public:/var/www/lintello/public
      - node_modules:/var/www/lintello/frontend/node_modules
    command: sh -c "npm install && npm run dev"
    ports:
      - "5173:5173"
    networks:
      - lintello_network
    environment:
      - VITE_HOST=0.0.0.0

networks:
  lintello_network:
    driver: bridge

volumes:
  mysql_data:
  node_modules:
