
import { supabase } from '../client';

/**
 * 테이블 상태를 확인합니다.
 */
export const checkTablesStatus = async (): Promise<{
  transactions: boolean;
  budgets: boolean;
  category_budgets: boolean;
}> => {
  const tables = {
    transactions: false,
    budgets: false,
    category_budgets: false
  };
  
  try {
    // transactions 테이블 확인
    const { data: transactionsData, error: transactionsError } = await supabase
      .from('transactions')
      .select('*', { count: 'exact', head: true });
      
    tables.transactions = !transactionsError;
    
    // budgets 테이블 확인
    const { data: budgetsData, error: budgetsError } = await supabase
      .from('budgets')
      .select('*', { count: 'exact', head: true });
      
    tables.budgets = !budgetsError;
    
    // category_budgets 테이블 확인
    const { data: categoryBudgetsData, error: categoryBudgetsError } = await supabase
      .from('category_budgets')
      .select('*', { count: 'exact', head: true });
      
    tables.category_budgets = !categoryBudgetsError;
    
    return tables;
  } catch (error) {
    console.error('테이블 상태 확인 중 오류 발생:', error);
    return tables;
  }
};
