-- Quick Fix SQL for Token Deduction & Model Selector Issues
-- Run this in phpMyAdmin or XAMPP MySQL

USE ashlya_ashlya_academy_new;

-- Fix 1: Give all users 100 free tokens to start
UPDATE user 
SET ai_tokens_balance = 100.00,
    ai_tokens_purchased = 100.00
WHERE ai_tokens_balance = 0.00;

-- Fix 2: Add is_active column to ai_models if missing
ALTER TABLE ai_models 
ADD COLUMN IF NOT EXISTS is_active TINYINT(1) DEFAULT 1;

-- Fix 3: Ensure all models are active
UPDATE ai_models SET is_active = 1 WHERE is_active IS NULL;

-- Verification queries
SELECT COUNT(*) as users_with_tokens FROM user WHERE ai_tokens_balance > 0;
SELECT COUNT(*) as active_models FROM ai_models WHERE is_active = 1;
