import { supabase } from "@/integrations/supabase/client";

/**
 * Pulls budgets from Buildium for one or more associations.
 * Buildium's `/v1/budgets` endpoint exposes monthly amounts per GL account.
 */
export async function pullBudgetsFromBuildium(
  selectedAssociationIds: string[],
  fiscalYear: number
) {
  const { data, error } = await supabase.functions.invoke("buildium-sync", {
    body: {
      syncType: "budgets",
      selectedAssociationIds,
      dateFrom: `${fiscalYear}-01-01`,
      dateTo: `${fiscalYear}-12-31`,
    },
  });
  if (error) return { success: false, error: error.message };
  return { success: true, data: data?.results?.budgets };
}
