// 创建参数相关
import { useMain as useOptionsHooks } from '@/views/modelTraining/index/hooks/options.ts'
import { ref } from 'vue'

export const useMain = () => {
  const {
    testDatasetListRequest,
    modelListRequest,
    platformRequest,
    trainDatasetListRequest
  } = useOptionsHooks()


  const models = ref([])
  const getModels = async () => {
    const res = await modelListRequest.request()
    if (res?.code == 200) {
      models.value = res?.models
    }
    return res
  }

  const platform = ref({})
  const getPlatform = async (moduleName: string) => {
    const res = await platformRequest.request(moduleName)
    if (res?.code == 200) {
      platform.value = res.data
    }
    return res
  }

  const testDataset = ref([])
  const getTestDataset = async () => {
    const res = await testDatasetListRequest.request()
    if (res?.code == 200) {
      testDataset.value = res.data?.datasets
    }
    return res
  }

  const trainDataset = ref([])
  const getTrainDataset = async () => {
    const res = await trainDatasetListRequest.request()
    if (res?.code == 200) {
      trainDataset.value = res.data?.datasets
    }
    return res
  }

  const optionsLoading = ref(false)
  const getOptions = async () => {
    optionsLoading.value = true
    const res = await Promise.all([
      getModels(),
      getTestDataset(),
      getTrainDataset(),
    ])
    optionsLoading.value = false
  }

  // 导出选项
  const exportOptions = [
    {
      label: "ONNX",
      value: "ONNX",
    },
    {
      label: "PT",
      value: "PT",
    },
    {
      label: "PTH",
      value: "PTH",
    },
  ]



  const state = {
    models,
    exportOptions,
    platform,
    testDataset,
    trainDataset,
    optionsLoading
  }


  return {
    state: state,
    api: {
      getModels,
      getPlatform,
      getTestDataset,
      getTrainDataset,
      getOptions,
    },
    requestMap: {
      testDatasetListRequest,
      modelListRequest,
      platformRequest,
      trainDatasetListRequest
    }
  }
}
