<?php
// Supabase Configuration for CodexVertex

$supabase_url = "https://bxeogwxglszcxvewiyai.supabase.co";
$supabase_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImJ4ZW9nd3hnbHN6Y3h2ZXdpeWFpIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzI5OTcxNjcsImV4cCI6MjA4ODU3MzE2N30.1r0s7IK9JPcFqnIyPIlC4zAyHrQquf1pGk42g3nRODM";

/**
 * Executes a query to Supabase REST API
 */
function supabase_request($method, $path, $data = null) {
    global $supabase_url, $supabase_key;
    
    $url = $supabase_url . "/rest/v1/" . $path;
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
    
    $headers = [
        "apikey: $supabase_key",
        "Authorization: Bearer $supabase_key",
        "Content-Type: application/json",
        "Prefer: return=representation"
    ];
    
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    if ($data) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    }
    
    $response = curl_exec($ch);
    $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $curl_error = curl_error($ch);
    curl_close($ch);
    
    return [
        "status" => $status_code,
        "error" => $curl_error,
        "data" => json_decode($response, true)
    ];
}
?>
