#!/usr/bin/env bash
# Select which Firebase project the app talks to by copying that environment's
# config files into the Android and iOS projects.
#
# Usage:  firebase/use.sh dev|prod
set -euo pipefail

ENV="${1:-}"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
APP_DIR="$(dirname "$DIR")"

if [[ "$ENV" != "dev" && "$ENV" != "prod" ]]; then
  echo "usage: $0 dev|prod" >&2
  exit 1
fi

cp "$DIR/$ENV/google-services.json" "$APP_DIR/android/app/google-services.json"
cp "$DIR/$ENV/GoogleService-Info.plist" "$APP_DIR/ios/Runner/GoogleService-Info.plist"
echo "Firebase config switched to: $ENV"
