services:
  db:
    image: postgres:15-alpine
    container_name: postgres_db
    environment:
      POSTGRES_DB: isante_db
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - "5434:5432"
    networks:
      - isante_network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

  app:
    build:
      context: ./api
      dockerfile: Dockerfile.dev
    container_name: isante_app
    depends_on:
      db:
        condition: service_healthy
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/isante_db
      SPRING_PROFILES_ACTIVE: docker
      CORS_ALLOWED_ORIGINS: http://localhost:3000
    ports:
      - "8080:8080"
    volumes:
       - ./src:/app/src
    networks:
      - isante_network

  
  client:
    build:
      dockerfile: Dockerfile.dev
      context: ./client   
    ports:
      - 3000:3000    
    environment:
      - NODE_ENV=development
      - CHOKIDAR_USEPOLLING=true
      - WATCHPACK_POLLING=true 
      - NEXT_PUBLIC_API_URL=http://app:8080 # Communication interne Docker
      - NEXT_PUBLIC_API_BROWSER_URL=http://localhost:8080 # Accès depuis le navigateur
    
    depends_on:
    - app

    # env_file:
    #   - client/.env.local
    volumes:
      - ./client:/app:delegated
      - /app/node_modules
    networks:
      - isante_network


volumes:
  postgres_data:

networks:
  isante_network:
    driver: bridge