services:
  postgres:
    image: postgres:15-alpine
    container_name: lediscord_db
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - postgres_data_lediscord:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    networks:
      - lediscord_network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: lediscord_backend
    environment:
      # Variables spécifiques au docker-compose (peuvent surcharger .env)
      DB_PASSWORD: ${POSTGRES_PASSWORD}
      ENVIRONMENT: ${ENVIRONMENT}
      DEBUG: ${DEBUG}
      RELOAD: ${RELOAD}
      LOG_LEVEL: ${LOG_LEVEL}
      WORKERS: ${WORKERS}
      DATABASE_URL: ${DATABASE_URL}
      CORS_ORIGINS: ${CORS_ORIGINS}
      UPLOAD_PATH: ${UPLOAD_PATH}
      JWT_SECRET_KEY: ${JWT_SECRET_KEY}
      JWT_ALGORITHM: ${JWT_ALGORITHM}
      JWT_EXPIRATION_MINUTES: ${JWT_EXPIRATION_MINUTES}
      SMTP_HOST: ${SMTP_HOST}
      SMTP_PORT: ${SMTP_PORT}
      SMTP_USER: ${SMTP_USER}
      SMTP_PASSWORD: ${SMTP_PASSWORD}
      SMTP_FROM: ${SMTP_FROM}
      ADMIN_EMAIL: ${ADMIN_EMAIL}
      ADMIN_PASSWORD: ${ADMIN_PASSWORD}
      APP_NAME: ${APP_NAME}
      APP_URL: ${APP_URL}
      MAX_UPLOAD_SIZE: ${MAX_UPLOAD_SIZE}
      ALLOWED_IMAGE_TYPES: ${ALLOWED_IMAGE_TYPES}
      ALLOWED_VIDEO_TYPES: ${ALLOWED_VIDEO_TYPES}
      VAPID_PRIVATE_KEY: ${VAPID_PRIVATE_KEY}
      VAPID_PUBLIC_KEY: ${VAPID_PUBLIC_KEY}
    volumes:
      - ${UPLOAD_PATH:-./uploads}:/app/uploads
      - ./backend:/app
    ports:
      - "8002:8000"
    depends_on:
      postgres:
        condition: service_healthy
    networks:
      - lediscord_network
    restart: unless-stopped

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: lediscord_frontend
    environment:
      VITE_API_URL: ${VITE_API_URL}
      VITE_APP_URL: ${VITE_APP_URL}
      VITE_UPLOAD_URL: ${VITE_UPLOAD_URL}
    volumes: 
      - ./frontend:/app
      - /app/node_modules
    ports:
      - "8082:5173"
    networks:
      - lediscord_network
    restart: unless-stopped

networks:
  lediscord_network:
    driver: bridge

volumes:
  postgres_data_lediscord:
