import { ref } from 'vue';
import { getAIList, getManualList } from '@/api/datamanagement/alert'

type AIOption = {
  id: number
  name: string
};

type ManualOption = {
  id: number
  name: string
};

export function useIssueType() {
  // AI检测
  const aiOptions = ref<AIOption[]>([]);
  // 人工上报
  const manualOptions = ref<ManualOption[]>([]);

  const getAIOptions = () => {
    getAIList().then((res) => {
      res.forEach((item) => {
        aiOptions.value.push({
          id: item.id,
          name: item.name
        })
      });
    })
  };

  const getManualOptions = () => {
    getManualList().then((res) => {
      res.forEach((item) => {
        manualOptions.value.push({
          id: item.id,
          name: item.name
        })
      })
    })
  };

  // 根据 问题来源id + 问题类型id 决定表格类型栏展示文字
  const getNameByType = (source, type, arrayOfOptions) => {
    // arrayOfOptions = [ aiOptions, manualOptions ]
    const targetArray = arrayOfOptions[source - 1];
    const foundObject = targetArray.find(obj => obj.id === type);
    if (foundObject) return foundObject.name;
    else return '-'
  };

  return {
    aiOptions,
    manualOptions,
    getAIOptions,
    getManualOptions,
    getNameByType
  };
}