#!/usr/bin/env bash
# invyone 개발용 도커 컨테이너 기동 (리눅스)
# 사용법: ./invyone-start-docker-all.sh
# 실행권한 필요 시: chmod +x invyone-start-docker-all.sh

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
COMPOSE_FILE="$PROJECT_ROOT/docker/dev/docker-compose.invyone.yml"

if ! command -v docker >/dev/null 2>&1; then
  echo "[invyone] docker 가 설치되어있지 않습니다. Docker 설치 후 다시 실행해주세요."
  exit 1
fi

if ! docker info >/dev/null 2>&1; then
  echo "[invyone] docker daemon 이 실행 중이지 않습니다. Docker Desktop 또는 dockerd 를 실행해주세요."
  exit 1
fi

if [ ! -f "$COMPOSE_FILE" ]; then
  echo "[invyone] compose 파일을 찾을 수 없음: $COMPOSE_FILE"
  exit 1
fi

echo "[invyone] 도커 컨테이너 기동 중..."
docker compose -f "$COMPOSE_FILE" up -d

echo ""
echo "[invyone] 컨테이너 상태:"
docker compose -f "$COMPOSE_FILE" ps

echo ""
echo "[invyone] 접속 URL:"
echo "  Frontend:  http://localhost:9772"
echo "  Backend:   http://localhost:8083/api"
echo "  테넌트:    http://<subdomain>.localhost:9772  (예: http://test01.localhost:9772)"
echo ""
echo "[invyone] 로그 보기:      docker compose -f docker/dev/docker-compose.invyone.yml logs -f"
echo "[invyone] 컨테이너 내리기: docker compose -f docker/dev/docker-compose.invyone.yml down"
