import { create } from 'zustand'
import { persist } from 'zustand/middleware'
import { AppState } from '@/lib/types'
import { createDebtsSlice, DebtsSlice } from './store/slices/debtsSlice'
import { createCardsSlice, CardsSlice } from './store/slices/cardsSlice'
import { createBudgetSlice, BudgetSlice } from './store/slices/budgetSlice'
import { createAlertsSlice, AlertsSlice } from './store/slices/alertsSlice'

import { createServicesSlice, ServicesSlice } from './store/slices/servicesSlice'

// Combined State Interface
// Note: We extend the individual slices to create the full store interface
export interface FinanzasState extends DebtsSlice, CardsSlice, BudgetSlice, AlertsSlice, ServicesSlice { }

export const useFinanzasStore = create<FinanzasState>()(
  persist(
    (...a) => ({
      ...createDebtsSlice(...a),
      ...createCardsSlice(...a),
      ...createBudgetSlice(...a),
      ...createAlertsSlice(...a),
      ...createServicesSlice(...a),
    }),
    {
      name: 'finanzas-storage',
      // Optional: Filter what gets persisted if needed in the future
      // partialize: (state) => ({ ... }) 
    }
  )
)
