#!/bin/bash
# Copy the correct GoogleService-Info.plist based on build configuration
# This script is run as a build phase in Xcode

# Determine flavor from build configuration name
FLAVOR=""
if [[ "${CONFIGURATION}" == *"local"* ]]; then
  FLAVOR="local"
elif [[ "${CONFIGURATION}" == *"demo"* ]]; then
  FLAVOR="demo"
elif [[ "${CONFIGURATION}" == *"dev"* ]]; then
  FLAVOR="dev"
else
  # Default to dev
  FLAVOR="dev"
fi

PLIST_SRC="${PROJECT_DIR}/config/${FLAVOR}/GoogleService-Info.plist"
PLIST_DEST="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/GoogleService-Info.plist"

if [ -f "$PLIST_SRC" ]; then
  echo "Copying GoogleService-Info.plist for flavor: ${FLAVOR}"
  cp "$PLIST_SRC" "$PLIST_DEST"
else
  echo "Warning: GoogleService-Info.plist not found for flavor: ${FLAVOR} at ${PLIST_SRC}"
  echo "Using default from Runner/"
fi
