import { createClient } from '@supabase/supabase-js';
import * as dotenv from 'dotenv';
import path from 'path';

dotenv.config({ path: path.resolve(process.cwd(), '.env') });

const supabase = createClient(process.env.SUPABASE_URL!, process.env.SUPABASE_KEY!);

async function testDirectInsert() {
    console.log('Testing Direct Insert...');
    console.log('URL:', process.env.SUPABASE_URL);
    console.log('Key (last 5):', process.env.SUPABASE_KEY?.slice(-5));

    const { data, error } = await supabase
        .from('orders')
        .insert([{
            user_id: '88a2446e-740f-4c87-a94c-fad0ee5167ba',
            symbol: 'DEBUG/TEST',
            type: 'Market',
            side: 'buy',
            qty: 1,
            price: 100,
            status: 'Filled',
            timestamp: Date.now()
        }])
        .select();

    if (error) {
        console.error('❌ Insert Error:', error);
    } else {
        console.log('✅ Insert Success:', data);
    }
}

testDirectInsert();
