import { createClient } from '@supabase/supabase-js';
import { config } from '../config.js';
import { getSqliteClient } from '../db/sqlite-client.js';
import { getSqlitePath } from './data-dir.js';
/**
 * The gateway has two storage backends:
 *   - 'device' (default): local SQLite via better-sqlite3 + sqlite-vec
 *   - 'control-plane': Supabase Postgres via @supabase/supabase-js
 *
 * Both clients expose the same chained-query API (see src/db/sqlite-client.ts).
 * We type the export as SupabaseClient because that's the public shape the rest
 * of the gateway has been written against — the SQLite shim is a structural
 * lookalike that covers the methods actually used. Runtime behavior is correct
 * for both modes; TypeScript stays happy with downstream type inference.
 */
function buildClient() {
    if (config.MUASSIS_MODE === 'device') {
        return getSqliteClient(getSqlitePath());
    }
    return createClient(config.SUPABASE_URL, config.SUPABASE_SERVICE_ROLE_KEY, {
        auth: { persistSession: false },
    });
}
// Service role client — full access (server-side only).
// In device mode this is the SQLite client (privileged calls only happen server-side).
export const supabase = buildClient();
// Anon client — only meaningful in control-plane mode (used by Supabase Auth OTP routes).
// In device mode there is no anon client; auth routes that depend on this must be skipped
// or stubbed. We export the same instance so existing imports compile; runtime behavior
// is gated by MUASSIS_MODE checks in the auth routes.
export const supabaseAnon = config.MUASSIS_MODE === 'device'
    ? supabase
    : createClient(config.SUPABASE_URL, config.SUPABASE_ANON_KEY, {
        auth: { persistSession: false },
    });
//# sourceMappingURL=supabase.js.map