import {create} from 'zustand'
import type {LightBacktestResponse} from '../../generated/ManagingApi'

interface BacktestStore {
  backtests: LightBacktestResponse[]
  isLoading: boolean
  setBacktests: (backtests: LightBacktestResponse[]) => void
  addBacktest: (backtest: LightBacktestResponse) => void
  removeBacktest: (id: string) => void
  setLoading: (loading: boolean) => void
  clearBacktests: () => void
}

const useBacktestStore = create<BacktestStore>((set, get) => ({
  backtests: [],
  isLoading: false,
  
  setBacktests: (backtests: LightBacktestResponse[]) => 
    set({ backtests }),
  
  addBacktest: (backtest: LightBacktestResponse) =>
    set((state) => ({ 
      backtests: [...state.backtests, backtest] 
    })),
  
  removeBacktest: (id: string) =>
    set((state) => ({ 
      backtests: state.backtests.filter(backtest => 
        String(backtest.id) !== String(id)
      ) 
    })),
  
  setLoading: (loading: boolean) =>
    set({ isLoading: loading }),
  
  clearBacktests: () =>
    set({ backtests: [] })
}))

export default useBacktestStore 