services:
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    volumes:
      - .:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - laravel-app
    networks:
      - innovatieplatform

  laravel-app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    volumes:
      - .:/var/www/html
    environment:
      - APP_ENV=${APP_ENV:-local}
      - APP_KEY=${APP_KEY}
      - DB_CONNECTION=pgsql
      - DB_HOST=postgresql
      - DB_PORT=5432
      - DB_DATABASE=${DB_DATABASE:-innovatieplatform}
      - DB_USERNAME=${DB_USERNAME:-innovatie}
      - DB_PASSWORD=${DB_PASSWORD:-secret}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - AI_SERVICE_URL=http://ai-service:8000
    depends_on:
      postgresql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - innovatieplatform

  laravel-worker:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    command: php artisan queue:work --sleep=3 --tries=3 --max-time=3600
    volumes:
      - .:/var/www/html
    environment:
      - APP_ENV=${APP_ENV:-local}
      - APP_KEY=${APP_KEY}
      - DB_CONNECTION=pgsql
      - DB_HOST=postgresql
      - DB_PORT=5432
      - DB_DATABASE=${DB_DATABASE:-innovatieplatform}
      - DB_USERNAME=${DB_USERNAME:-innovatie}
      - DB_PASSWORD=${DB_PASSWORD:-secret}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - AI_SERVICE_URL=http://ai-service:8000
    depends_on:
      postgresql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - innovatieplatform

  laravel-scheduler:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    entrypoint: ["/usr/local/bin/scheduler-entrypoint.sh"]
    volumes:
      - .:/var/www/html
      - ./docker/scheduler/entrypoint.sh:/usr/local/bin/scheduler-entrypoint.sh
    environment:
      - APP_ENV=${APP_ENV:-local}
      - APP_KEY=${APP_KEY}
      - DB_CONNECTION=pgsql
      - DB_HOST=postgresql
      - DB_PORT=5432
      - DB_DATABASE=${DB_DATABASE:-innovatieplatform}
      - DB_USERNAME=${DB_USERNAME:-innovatie}
      - DB_PASSWORD=${DB_PASSWORD:-secret}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
    depends_on:
      postgresql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - innovatieplatform

  postgresql:
    image: pgvector/pgvector:pg16
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_DB=${DB_DATABASE:-innovatieplatform}
      - POSTGRES_USER=${DB_USERNAME:-innovatie}
      - POSTGRES_PASSWORD=${DB_PASSWORD:-secret}
    volumes:
      - postgresql_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USERNAME:-innovatie} -d ${DB_DATABASE:-innovatieplatform}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - innovatieplatform

  redis:
    image: redis:alpine
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - innovatieplatform

  ai-service:
    build:
      context: ./ai-service
      dockerfile: Dockerfile
    ports:
      - "8000:8000"
    volumes:
      - ./ai-service:/app
    environment:
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
      - ANTHROPIC_MODEL=${ANTHROPIC_MODEL:-claude-haiku-4-5-20251001}
      - DATABASE_URL=postgresql://${DB_USERNAME:-innovatie}:${DB_PASSWORD:-secret}@postgresql:5432/${DB_DATABASE:-innovatieplatform}
      - DB_HOST=postgresql
      - DB_PORT=5432
      - DB_DATABASE=${DB_DATABASE:-innovatieplatform}
      - DB_USERNAME=${DB_USERNAME:-innovatie}
      - DB_PASSWORD=${DB_PASSWORD:-secret}
    depends_on:
      postgresql:
        condition: service_healthy
    networks:
      - innovatieplatform

volumes:
  postgresql_data:
  redis_data:

networks:
  innovatieplatform:
    driver: bridge
