// lib/supabaseServer.ts
import { cookies } from "next/headers";
import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { createClient } from "@supabase/supabase-js";
// import type { Database } from "./types"; // si tu as un type généré

export function createSbServer() {
  // Si tu as un type Database, passe-le en générique : <Database>
  return createServerComponentClient({ cookies });
}

// Client Supabase avec service role pour les opérations serveur
export function createSbServiceRole() {
  const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL!;
  const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY!;
  
  return createClient(supabaseUrl, supabaseServiceRoleKey, {
    auth: {
      autoRefreshToken: false,
      persistSession: false
    }
  });
}