# Docker Compose pour build local (développement)
# Usage: docker-compose -f docker-compose.build.yml build

services:
  postgres:
    image: pgvector/pgvector:pg16
    container_name: audio_classifier_db
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-audio_user}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-audio_password}
      POSTGRES_DB: ${POSTGRES_DB:-audio_classifier}
    ports:
      - "5433:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./backend/init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-audio_user}"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  backend:
    build:
      context: .
      dockerfile: backend/Dockerfile
    container_name: audio_classifier_api
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER:-audio_user}:${POSTGRES_PASSWORD:-audio_password}@postgres:5432/${POSTGRES_DB:-audio_classifier}
      CORS_ORIGINS: ${CORS_ORIGINS:-*}
      ANALYSIS_USE_CLAP: ${ANALYSIS_USE_CLAP:-false}
      ANALYSIS_NUM_WORKERS: ${ANALYSIS_NUM_WORKERS:-4}
      ESSENTIA_MODELS_PATH: /app/models
    ports:
      - "8001:8000"
    volumes:
      # Mount your audio library (read-write for transcoding and waveforms)
      - ${AUDIO_LIBRARY_PATH:-./audio_samples}:/audio
    restart: unless-stopped

  frontend:
    build:
      context: .
      dockerfile: frontend/Dockerfile
      args:
        NEXT_PUBLIC_API_URL: http://localhost:8001
    container_name: audio_classifier_ui
    environment:
      # Use localhost:8001 because the browser (client-side) needs to access the API
      # The backend is mapped to port 8001 on the host machine
      NEXT_PUBLIC_API_URL: http://localhost:8001
    ports:
      - "3000:3000"
    depends_on:
      - backend
    restart: unless-stopped

volumes:
  postgres_data:
    driver: local
