#!/usr/bin/env bash
# 🚀 DEPLOY TILES TO FIREBASE HOSTING
# Moves tiles to the web app public folder and deploys hosting.

set -euo pipefail

# Configuration
TILES_SOURCE="public/tiles"
WEB_PUBLIC_DIR="apps/web/public/tiles"

echo "============================================="
echo "🔥 DEPLOYING TILES TO FIREBASE"
echo "============================================="

# 1. Move Tiles to Web Public Dir
echo "📦 Moving tiles to $WEB_PUBLIC_DIR..."
mkdir -p "$WEB_PUBLIC_DIR"
rsync -av --delete "$TILES_SOURCE/" "$WEB_PUBLIC_DIR/"

# 2. Deploy Hosting
echo "🚀 Deploying Firebase Hosting..."
# We assume firebase-tools is installed globally or locally
if command -v firebase &> /dev/null; then
    firebase deploy --only hosting
else
    echo "⚠️ 'firebase' command not found. Trying 'pnpm firebase'..."
    pnpm firebase deploy --only hosting
fi

echo "✅ Deployment complete!"
echo "   Tiles available at: https://[YOUR-FIREBASE-APP].web.app/tiles/{z}/{x}/{y}.pbf"
