#!/bin/bash

# ADD TEST CREDITS
# Gives you VAE balance instantly for testing

echo "💰 ADDING TEST CREDITS"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

# Load environment
source .env

# Get your user ID
echo "🔍 Finding your user account..."
YOUR_TELEGRAM_ID="${YOUR_TELEGRAM_ID:-123456789}"  # Set this in .env

node << 'EOF'
const { createClient } = require('@supabase/supabase-js');
const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_SERVICE_KEY);

async function addCredits() {
  // Find user by Telegram ID or create
  const telegramId = process.env.YOUR_TELEGRAM_ID || '123456789';
  
  let { data: user } = await supabase
    .from('app_users')
    .select('id')
    .eq('telegram_id', telegramId)
    .single();
  
  if (!user) {
    console.log('❌ User not found. Set YOUR_TELEGRAM_ID in .env');
    process.exit(1);
  }
  
  const userId = user.id;
  
  // Add requester credits (for posting tasks)
  await supabase
    .from('vae_balances')
    .update({ deposit_balance: 10000 })  // Ⓥ10,000 = $100
    .eq('user_id', userId);
  
  // Add worker credits (for testing completions)
  await supabase
    .from('vae_balances')
    .update({ earned_balance: 1000 })  // Ⓥ1,000 = $10
    .eq('user_id', userId);
  
  console.log('✅ Added test credits:');
  console.log('   Requester: Ⓥ10,000 ($100)');
  console.log('   Worker: Ⓥ1,000 ($10)');
  console.log('');
  console.log('📝 Now you can:');
  console.log('   - Post tasks on WhatsApp');
  console.log('   - Complete tasks on Telegram');
  console.log('   - Withdraw $1 to test payments');
  process.exit(0);
}

addCredits().catch(err => {
  console.error('❌ Error:', err.message);
  process.exit(1);
});
EOF

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ DONE!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
