import {ref} from "vue";
import {FormSchema} from "@/types/form";
import {ElTag} from "element-plus";

export enum ProviderEnum {
  Redis = 'REDIS',
  PgVector = 'PGVECTOR',
  Milvus = 'MILVUS',
}


export default function () {
  const ProviderConst = [
    { label: 'Redis', value: ProviderEnum.Redis },
    { label: 'PgVector', value: ProviderEnum.PgVector },
    { label: 'Milvus', value: ProviderEnum.Milvus },
  ];
  function getProviderLabel(value: any) {
    const arr = ProviderConst.filter((i) => i.value === value);
    if (arr === undefined || arr.length === 0) {
      return value;
    }
    return arr[0].label;
  }
  const shema = ref<FormSchema[]>([
    {
      label: '模型名称',
      field: 'name',
      component: 'Input',
      colProps: {
        span: 6
      },
    }
  ])
  const columns = ref<object[]>([
    {
      label: '数据库别名',
      field: 'name',
      align: 'center',
    },
    {
      label: '供应商',
      field: 'provider',
      align: 'center',
      width: '120',
      render(row) {
        return h(
          ElTag,
          {
            type: 'success',
          },
          {
            default: () => getProviderLabel(row.provider),
          }
        );
      },
    },
    {
      label: '向量纬度',
      field: 'dimension',
      align: 'center',
      width: '80',
      render(row) {
        return h(
          ElTag,
          {
            size: 'small',
          },
          {
            default: () => row.dimension,
          }
        );
      },
    },
    {
      label: '数据库地址',
      field: 'host',
      align: 'center',
      width: '110',
    },
    {
      label: '数据库端口',
      field: 'port',
      align: 'center',
      width: '100',
    },
    {
      label: '数据库用户名',
      field: 'username',
      align: 'center',
    },
    {
      label: '数据库密码',
      field: 'password',
      align: 'center',
    },
    {
      label: '数据库名',
      field: 'databaseName',
      align: 'center',
    },
    {
      label: '表名称',
      field: 'tableName',
      align: 'center',
    },
  ])
  const tableData = ref([])
  return {
    ProviderConst,
    getProviderLabel,
    shema,
    columns,
    tableData
  }
}
