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

export const PayableRemovalService = {
  async cleanupOldPayables(payee, billDate) {
    // Update payables to mark as paid
    const { error } = await supabase
      .from('payables')
      .update({ status: 'paid' })
      .eq('vendor_name', payee)
      .lte('due_date', billDate);
    
    if (error) {
      console.error('Error cleaning up old payables:', error);
      throw error;
    }
  },

  async getRemovalLogs() {
    const { data, error } = await supabase
      .from('payables')
      .select('*')
      .eq('status', 'paid')
      .order('updated_at', { ascending: false });
    
    if (error) throw error;
    return data;
  },

  async restorePayable(payableId) {
    const { error } = await supabase
      .from('payables')
      .update({ status: 'pending' })
      .eq('id', payableId);

    if (error) throw error;
  }
};
