#!/bin/bash
set -euo pipefail

PROJECT_DIR="/opt/projects/bogazici/corporate-admin/test/admin"
BRANCH="test"
CONTAINER="bdc-admin-test"
COMPOSE_FILE="docker-compose.test.yml"

echo "🚀 [Admin] Test deploy başlatılıyor..."

cd "$PROJECT_DIR"

# Git sync
git fetch origin
git checkout "$BRANCH"
git reset --hard "origin/$BRANCH"
git clean -fd

# Docker - stop & remove any existing container first
docker stop "$CONTAINER" 2>/dev/null || true
docker rm "$CONTAINER" 2>/dev/null || true
docker compose -f "$COMPOSE_FILE" down --remove-orphans 2>/dev/null || true
docker compose -f "$COMPOSE_FILE" up -d --build

# Cleanup
docker image prune -f 2>/dev/null || true

echo "✅ [Admin] Test deploy tamamlandı"
