import { ref } from 'vue'
import { getModelByDatasetApi, getPerformanceApi } from '@/apis/train/performance.ts'

export const useMain = () => {
  const getModelByDatasetLoading = ref(false)
  const getModelByDataset = async (datasetName: string) => {
    if (getModelByDatasetLoading.value) return false
    getModelByDatasetLoading.value = true
    const res = await getModelByDatasetApi(datasetName).catch(err => {
      return err
    })
    getModelByDatasetLoading.value = false
    return res
  }

  const performanceLoading = ref(false)
  const getPerformance = async (data: Record<string, any>) => {
    if (performanceLoading.value) return false
    performanceLoading.value = true
    const res = await getPerformanceApi(data).catch(err => {
      return err
    })
    performanceLoading.value = false
    return res
  }

  return {
    getModelByDatasetRequest: {
      request: getModelByDataset,
      loading: getModelByDatasetLoading
    },
    getPerformanceRequest: {
      request: getPerformance,
      loading: performanceLoading
    }
  }
}
