#!/bin/bash

# GROQ API Key Setup Helper
echo "================================================"
echo "  GROQ API Key Setup for BondaCare Chatbot"
echo "================================================"
echo ""
echo "Step 1: Get your GROQ API key"
echo "   → Go to: https://console.groq.com/"
echo "   → Sign up (free)"
echo "   → Click 'API Keys' → 'Create API Key'"
echo "   → Copy the key (starts with gsk_...)"
echo ""
echo "Step 2: Enter your GROQ API key below"
echo ""
read -p "Paste your GROQ API key: " GROQ_KEY

if [ -z "$GROQ_KEY" ]; then
    echo "❌ No key entered. Exiting."
    exit 1
fi

# Update .env file
cd /Users/mirzarusyaidi/bondacare

# Check if GROQ_API_KEY already exists
if grep -q "GROQ_API_KEY=" .env; then
    # Replace existing key
    sed -i '' "s/GROQ_API_KEY=.*/GROQ_API_KEY=$GROQ_KEY/" .env
    echo "✅ Updated existing GROQ_API_KEY in .env"
else
    # Add new key
    echo "GROQ_API_KEY=$GROQ_KEY" >> .env
    echo "✅ Added GROQ_API_KEY to .env"
fi

# Clear cache
php artisan config:clear
php artisan cache:clear

echo ""
echo "================================================"
echo "✅ GROQ Setup Complete!"
echo "================================================"
echo ""
echo "Your chatbot is now using GROQ API (super fast!)"
echo ""
echo "Test it now:"
echo "  1. Open your BondaCare website"
echo "  2. Click the chatbot"
echo "  3. Ask a question - it should respond in 1-2 seconds!"
echo ""
echo "Available models:"
echo "  - llama-3.3-70b-versatile (Current - Best balance)"
echo "  - llama-3.1-8b-instant (Fastest)"
echo "  - mixtral-8x7b-32768 (For long chats)"
echo ""
