import KFIcon from '@/components/KFIcon';
import { CommonTabKeys } from '@/enums';
import {
  addDatasetVersionDetail,
  addModelsVersionDetail,
  deleteDataset,
  deleteDatasetVersion,
  deleteModel,
  deleteModelVersion,
  getDatasetById,
  getDatasetList,
  getDatasetVersionIdList,
  getDatasetVersionsById,
  getModelById,
  getModelList,
  getModelVersionIdList,
  getModelVersionsById,
} from '@/services/dataset/index.js';
import type { TabsProps } from 'antd';

export enum ResourceType {
  Model = 'Model', // 模型
  Dataset = 'Dataset', // 数据集
}

type ResourceTypeInfo = {
  getList: (params: any) => Promise<any>; // 获取资源列表
  getVersions: (params: any) => Promise<any>; // 获取版本列表
  getFiles: (params: any) => Promise<any>; // 获取版本下的文件列表
  deleteRecord: (params: any) => Promise<any>; // 删除
  addVersion: (params: any) => Promise<any>; // 新增版本
  deleteVersion: (params: any) => Promise<any>; // 删除版本
  getInfo: (params: any) => Promise<any>; // 获取详情
  name: string; // 名称
  typeParamKey: string; // 类型参数名称，获取资源列表接口使用
  tagParamKey: string; // 标签参数名称，获取资源列表接口使用
  fileReqParamKey: 'models_id' | 'dataset_id'; // 文件请求参数名称，获取文件列表接口使用
  tabItems: TabsProps['items']; // tab 列表
  typeTitle: string; // 类型标题
  tagTitle: string; // 标签标题
  typeValue: number; // 从 getAssetIcon 接口获取特定值的数据为 type 分类 （category_id === typeValue）
  tagValue: number; // 从 getAssetIcon 接口获取特定值的数据为 tag 分类（category_id === tagValue）
  prefix: string; // 图片资源、详情 url 的前缀
  deleteModalTitle: string; // 删除弹框的title
  addBtnTitle: string; // 新增按钮的title
  idParamKey: 'models_id' | 'dataset_id'; // 新建版本、删除版本接口，版本 id 的参数名称
  uploadAction: string; // 上传接口 url
  uploadAccept?: string; // 上传文件类型
  downloadAllAction: string; // 批量下载接口 url
  downloadSingleAction: string; // 单个下载接口 url
  infoTypePropertyName: string; // 详情数据中，类型属性名称
  infoTagPropertyName: string; // 详情数据中，标签属性名称
};

export const resourceConfig: Record<ResourceType, ResourceTypeInfo> = {
  [ResourceType.Dataset]: {
    getList: getDatasetList,
    getVersions: getDatasetVersionsById,
    getFiles: getDatasetVersionIdList,
    deleteRecord: deleteDataset,
    addVersion: addDatasetVersionDetail,
    deleteVersion: deleteDatasetVersion,
    getInfo: getDatasetById,
    name: '数据集',
    typeParamKey: 'data_type',
    tagParamKey: 'data_tag',
    fileReqParamKey: 'dataset_id',
    tabItems: [
      {
        key: CommonTabKeys.Public,
        label: '数据广场',
        icon: <KFIcon type="icon-shujuguangchang" />,
      },
      {
        key: CommonTabKeys.Private,
        label: '个人数据',
        icon: <KFIcon type="icon-gerenshuju" />,
      },
    ],
    typeTitle: '分类',
    tagTitle: '研究方向/应用领域',
    typeValue: 1,
    tagValue: 2,
    prefix: 'dataset',
    deleteModalTitle: '确定删除该条数据集实例吗？',
    addBtnTitle: '新建数据集',
    idParamKey: 'dataset_id',
    uploadAction: '/api/mmp/dataset/upload',
    uploadAccept: '.zip,.tgz',
    downloadAllAction: '/api/mmp/dataset/downloadAllFilesl',
    downloadSingleAction: '/api/mmp/dataset/download',
    infoTypePropertyName: 'dataset_type_name',
    infoTagPropertyName: 'dataset_tag_name',
  },
  [ResourceType.Model]: {
    getList: getModelList,
    getVersions: getModelVersionsById,
    getFiles: getModelVersionIdList,
    deleteRecord: deleteModel,
    addVersion: addModelsVersionDetail,
    deleteVersion: deleteModelVersion,
    getInfo: getModelById,
    name: '模型',
    typeParamKey: 'model_type',
    tagParamKey: 'model_tag',
    fileReqParamKey: 'models_id',
    tabItems: [
      {
        key: CommonTabKeys.Public,
        label: '模型广场',
        icon: <KFIcon type="icon-moxingguangchang" />,
      },
      {
        key: CommonTabKeys.Private,
        label: '个人模型',
        icon: <KFIcon type="icon-gerenmoxing" />,
      },
    ],
    typeTitle: '模型框架',
    tagTitle: '模型能力',
    typeValue: 3,
    tagValue: 4,
    prefix: 'model',
    deleteModalTitle: '确定删除该条模型实例吗？',
    addBtnTitle: '新建模型',
    idParamKey: 'models_id',
    uploadAction: '/api/mmp/models/upload',
    uploadAccept: undefined,
    downloadAllAction: '/api/mmp/models/downloadAllFiles',
    downloadSingleAction: '/api/mmp/models/download_model',
    infoTypePropertyName: 'model_type_name',
    infoTagPropertyName: 'model_tag_name',
  },
};

// 分类数据
export type CategoryData = {
  id: number;
  category_id: number;
  name: string;
  path: string;
};

// 资源数据
export type ResourceData = {
  id: number;
  name: string;
  description: string;
  create_by: string;
  update_time: string;
  available_range: number;
  model_type_name?: string;
  model_tag_name?: string;
  dataset_type_name?: string;
  dataset_tag_name?: string;
};

// 版本数据
export type ResourceVersionData = {
  label: string;
  value: string;
};

// 版本文件数据
export type ResourceFileData = {
  id: number;
  file_name: string;
  file_size: string;
  description: string;
  create_by: string;
  create_time: string;
  update_by: string;
  update_time: string;
  url: string;
  version: string;
};
