#!/bin/bash
STRIPE_KEY="sk_test_51SIwGl2WZb9MHlLoM0tvnneH7zdQJDLq4Ub7bmpK1mxZspvGKiMpEhvOYAXn8ZNYtRBvfoQZIObHuzQp89KLp1N300Jtko6flq"

# Exchange rates from lib/utils/currency.ts
# GBP: 1.00
# SAR: 4.76 (Saudi Arabia)
# AED: 4.66 (UAE)
# QAR: 4.62 (Qatar) - Already done
# KWD: 0.39 (Kuwait)
# BHD: 0.48 (Bahrain)
# OMR: 0.49 (Oman)

# Base prices in GBP
TIER1_GBP=179
TIER2_GBP=209
TIER3_GBP=249
TIER4_GBP=349
TIER5_GBP=449

# Product IDs
PROD_TIER1="prod_TNf1iF9UkLTD9u"
PROD_TIER2="prod_TNf1u5lJYQutnv"
PROD_TIER3="prod_TNf1RZVMy8XP4p"
PROD_TIER4="prod_TNf1HMUhxmVbZq"
PROD_TIER5="prod_TNf1BCDtDWWWN4"

echo "Creating GCC currency prices with proper conversion..."
echo "================================================"
echo ""

create_price() {
  local product=$1
  local tier=$2
  local currency=$3
  local amount=$4
  
  echo "Creating $tier - $currency $amount/month..."
  
  curl -s https://api.stripe.com/v1/prices \
    -u "$STRIPE_KEY": \
    -d "product=$product" \
    -d "currency=$currency" \
    -d "unit_amount=$amount" \
    -d "recurring[interval]=month" \
    -d "metadata[tier_id]=$tier" \
    -d "metadata[billing_period]=monthly" \
    -d "metadata[currency]=$currency" \
    | jq -r '"\(.id) - \(.currency) \(.unit_amount/100)"'
}

echo "🇸🇦 SAUDI ARABIA (SAR) - Rate: 4.76"
echo "-----------------------------------"
create_price "$PROD_TIER1" "tier1" "sar" "$((179 * 476))"  # 85204 = SAR 852.04
create_price "$PROD_TIER2" "tier2" "sar" "$((209 * 476))"  # 99484 = SAR 994.84
create_price "$PROD_TIER3" "tier3" "sar" "$((249 * 476))"  # 118524 = SAR 1185.24
create_price "$PROD_TIER4" "tier4" "sar" "$((349 * 476))"  # 166124 = SAR 1661.24
create_price "$PROD_TIER5" "tier5" "sar" "$((449 * 476))"  # 213724 = SAR 2137.24
echo ""

echo "🇦🇪 UAE (AED) - Rate: 4.66"
echo "-----------------------------------"
create_price "$PROD_TIER1" "tier1" "aed" "$((179 * 466))"  # 83414 = AED 834.14
create_price "$PROD_TIER2" "tier2" "aed" "$((209 * 466))"  # 97394 = AED 973.94
create_price "$PROD_TIER3" "tier3" "aed" "$((249 * 466))"  # 116034 = AED 1160.34
create_price "$PROD_TIER4" "tier4" "aed" "$((349 * 466))"  # 162634 = AED 1626.34
create_price "$PROD_TIER5" "tier5" "aed" "$((449 * 466))"  # 209234 = AED 2092.34
echo ""

echo "🇰🇼 KUWAIT (KWD) - Rate: 0.39"
echo "-----------------------------------"
create_price "$PROD_TIER1" "tier1" "kwd" "$((179 * 39))"   # 6981 = KWD 69.81
create_price "$PROD_TIER2" "tier2" "kwd" "$((209 * 39))"   # 8151 = KWD 81.51
create_price "$PROD_TIER3" "tier3" "kwd" "$((249 * 39))"   # 9711 = KWD 97.11
create_price "$PROD_TIER4" "tier4" "kwd" "$((349 * 39))"   # 13611 = KWD 136.11
create_price "$PROD_TIER5" "tier5" "kwd" "$((449 * 39))"   # 17511 = KWD 175.11
echo ""

echo "🇧🇭 BAHRAIN (BHD) - Rate: 0.48"
echo "-----------------------------------"
create_price "$PROD_TIER1" "tier1" "bhd" "$((179 * 48))"   # 8592 = BHD 85.92
create_price "$PROD_TIER2" "tier2" "bhd" "$((209 * 48))"   # 10032 = BHD 100.32
create_price "$PROD_TIER3" "tier3" "bhd" "$((249 * 48))"   # 11952 = BHD 119.52
create_price "$PROD_TIER4" "tier4" "bhd" "$((349 * 48))"   # 16752 = BHD 167.52
create_price "$PROD_TIER5" "tier5" "bhd" "$((449 * 48))"   # 21552 = BHD 215.52
echo ""

echo "🇴🇲 OMAN (OMR) - Rate: 0.49"
echo "-----------------------------------"
create_price "$PROD_TIER1" "tier1" "omr" "$((179 * 49))"   # 8771 = OMR 87.71
create_price "$PROD_TIER2" "tier2" "omr" "$((209 * 49))"   # 10241 = OMR 102.41
create_price "$PROD_TIER3" "tier3" "omr" "$((249 * 49))"   # 12201 = OMR 122.01
create_price "$PROD_TIER4" "tier4" "omr" "$((349 * 49))"   # 17101 = OMR 171.01
create_price "$PROD_TIER5" "tier5" "omr" "$((449 * 49))"   # 22001 = OMR 220.01
echo ""

echo "✅ All GCC currency prices created!"
