services:

  api:
    build: .
    container_name: neda_api
    ports:
      - "8000:8000"
    volumes:
      - "./:/app"
    env_file:
      - .env
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      livekit:
        condition: service_started
    restart: always

  postgres:
    image: postgres:17-alpine
    container_name: neda_postgres
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    restart: always

    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}" ]
      interval: 5s
      timeout: 5s
      retries: 3

  redis:
    image: redis:7-alpine
    container_name: neda_redis
    volumes:
      - redis_data:/data
    restart: always

    healthcheck:
      test: [ "CMD", "redis-cli", "ping" ]
      interval: 5s
      timeout: 3s
      retries: 5

  livekit:
    image: livekit/livekit-server
    container_name: neda_livekit
    ports:
      - "7780:7880"
      - "7781:7881"
      - "50000-50100:50000-50100/udp"
    env_file:
      - .env
    volumes:
      - ./livekit.yaml:/etc/livekit/livekit.yaml
    command: [ "--config", "/etc/livekit/livekit.yaml", "--keys", "${LIVEKIT_API_KEY}: ${LIVEKIT_API_SECRET}" ]
    restart: always

  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: neda_pgadmin
    restart: always
    ports:
      - "5050:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD}
      PGADMIN_CONFIG_SERVER_MODE: 'True'
      PGADMIN_CONFIG_UPGRADE_CHECK_ENABLED: 'False'
      PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False'
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    depends_on:
      - postgres

volumes:
  postgres_data:
  redis_data:
  pgadmin_data:
