// configDataService.js
export const ConfigDataService = {
  // 初始化配置数据

  initConfigData() {
    return [
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "inputPath",
        paramChineseName: "输入文件地址",
        paramType: "String",
        paramSort: "1",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: true
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "outputPath",
        paramChineseName: "输出文件地址",
        paramType: "String",
        paramSort: "2",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: true
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "exePath",
        paramChineseName: "模型地址",
        paramType: "String",
        paramSort: "3",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: true
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "modelData",
        paramChineseName: "输入参数",
        paramType: "txt",
        paramSort: "4",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: false
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "modelData",
        paramChineseName: "输入参数",
        paramType: "txt",
        paramSort: "4",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: false
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "modelData",
        paramChineseName: "输入参数",
        paramType: "txt",
        paramSort: "4",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: false
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "isNoise",
        paramChineseName: "是否加噪",
        paramType: "Boolean",
        paramSort: "5",
        paramDefaultValue: false,
        paramDescription: "",
        isRequired: false
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "noiseType",
        paramChineseName: "噪声类型",
        paramType: "select",
        paramSort: "6",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: false
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "noiseModel",
        paramChineseName: "噪声模型",
        paramType: "select",
        paramSort: "7",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: false
      }
    ];
  },

  // 生成唯一ID
  generateUniqueId() {
    return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
      const r = Math.random() * 16 | 0;
      const v = c === 'x' ? r : (r & 0x3 | 0x8);
      return v.toString(16);
    });
  },

  // 克隆配置数据
  cloneConfigData(configData) {
    if (!Array.isArray(configData)) {
      return this.initConfigData();
    }

    return configData.map(item => ({
      ...item,
      paramId: this.generateUniqueId(),
      createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
      updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
      createBy: null,
      updateBy: null
    }));
  },

  // 创建新的配置项
  createNewConfigItem() {
    return {
      modelId: '',
      paramName: '',
      paramChineseName: '',
      paramType: '',
      paramSort: '',
      paramDefaultValue: '',
      paramDescription: '',
      isRequired: false
    };
  },
  initinfoData() {
    return [
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "inputPath",
        paramChineseName: "输入文件地址",
        paramType: "String",
        paramSort: "1",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: true
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "outputPath",
        paramChineseName: "输出文件地址",
        paramType: "String",
        paramSort: "2",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: true
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "exePath",
        paramChineseName: "模型地址",
        paramType: "String",
        paramSort: "3",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: true
      },
      {
        createBy: null,
        createTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        updateBy: null,
        updateTime: new Date().toISOString().slice(0, 19).replace('T', ' '),
        remark: null,
        paramId: this.generateUniqueId(),
        modelId: "",
        paramName: "诊断数据",
        paramChineseName: "输入参数",
        paramType: "file",
        paramSort: "4",
        paramDefaultValue: "",
        paramDescription: "",
        isRequired: false
      },
    ];
  },
};
