#!/bin/bash
# Fix Daily Notification Plugin Podspec Name
# Creates a podspec with the expected name for Capacitor sync

PLUGIN_DIR="node_modules/@timesafari/daily-notification-plugin"
PODSPEC_ACTUAL="CapacitorDailyNotification.podspec"
PODSPEC_EXPECTED="TimesafariDailyNotificationPlugin.podspec"

if [ -f "$PLUGIN_DIR/$PODSPEC_ACTUAL" ] && [ ! -f "$PLUGIN_DIR/$PODSPEC_EXPECTED" ]; then
  echo "Creating podspec: $PODSPEC_EXPECTED"
  cat > "$PLUGIN_DIR/$PODSPEC_EXPECTED" << 'EOF'
require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

Pod::Spec.new do |s|
  s.name = 'TimesafariDailyNotificationPlugin'
  s.version = package['version']
  s.summary = package['description']
  s.license = package['license']
  s.homepage = package['repository']['url']
  s.author = package['author']
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
  s.ios.deployment_target  = '13.0'
  s.dependency 'Capacitor'
  s.swift_version = '5.1'
end
EOF
  echo "✓ Podspec created successfully"
elif [ -f "$PLUGIN_DIR/$PODSPEC_EXPECTED" ]; then
  echo "ℹ Podspec already exists"
else
  echo "⚠ Actual podspec not found at $PLUGIN_DIR/$PODSPEC_ACTUAL"
fi
