import { NextResponse } from "next/server";
import { sitePreferencesService } from "@/services/preferences/site-preferences.service";

export async function GET() {
  try {
    // Récupérer les préférences globales du site (pas besoin d'authentification)
    const sitePreferences = await sitePreferencesService.getSitePreferences();

    // Si elles n'existent pas, retourner des valeurs par défaut
    if (!sitePreferences) {
      return NextResponse.json({
        homeBackground: null,
        eventsBackground: null,
        leaderboardBackground: null,
      });
    }

    return NextResponse.json({
      homeBackground: sitePreferences.homeBackground,
      eventsBackground: sitePreferences.eventsBackground,
      leaderboardBackground: sitePreferences.leaderboardBackground,
    });
  } catch (error) {
    console.error("Error fetching preferences:", error);
    return NextResponse.json(
      {
        homeBackground: null,
        eventsBackground: null,
        leaderboardBackground: null,
      },
      { status: 200 }
    );
  }
}
