import { dayjs } from '@nocobase/utils';
import { lowerCase } from 'lodash';

/**
 * 为json对象中collections节点的name、title属性添加后缀
 * 为json对象中fields节点的collectionName、through、target性添加后缀
 * @param jsonObj json对象
 * @param appendText 后缀文本
 */
export function appendJsonCollectionName(jsonObj: any, appendText: string) {
  appendCollectionsNode(jsonObj, appendText);
  for (const item of jsonObj['collections'][0]['fields']) {
    appendFieldsNode(item, appendText);
  }
  return jsonObj;
}

function appendCollectionsNode(jsonObj: any, appendText: string) {
  jsonObj['collections'][0]['name'] += appendText;
  jsonObj['collections'][0]['title'] += appendText;
}
function appendFieldsNode(jsonObj: any, appendText: string) {
  for (const key in jsonObj) {
    if (key === 'collectionName' || key === 'through' || key === 'target') {
      jsonObj[key] += appendText;
    }
  }
}
/**
 * @returns 生成3位随机小写字母
 */
export function generateRandomLetters() {
  let result = '';
  const characters = 'abcdefghijklmnopqrstuvwxyz';
  for (let i = 0; i < 3; i++) {
    result += characters.charAt(Math.floor(Math.random() * characters.length));
  }
  return result;
}
/**
 * builtin_ 为NocoBase内置模板，同NocoBase在页面创建效果一致主要用法3种：
 *  1是测试用例仅需一个无业务字段的表即可验证，
 *  2是作为多对多的中间表，
 *  3是存在先表后关系字段的情况，使用create内置模板表再update表的方式更新数据表来添加全部字段
 * e2e_ 按照不同场景的数据表，可以多个测试用例共用一个或一套数据表
 */
export const builtin_General = {
  collections: [
    {
      key: 'hqh4qy21m46',
      name: 'tt_amt_org',
      title: '自动>组织[普通表]',
      inherit: false,
      hidden: false,
      description: null,
      fields: [
        {
          key: 'z3fvals50xp',
          name: 'id',
          type: 'bigInt',
          interface: 'id',
          description: null,
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          autoIncrement: true,
          primaryKey: true,
          allowNull: false,
          uiSchema: {
            type: 'number',
            title: '{{t("ID")}}',
            'x-component': 'InputNumber',
            'x-read-pretty': true,
          },
        },
        {
          key: '3cp1zy4ogle',
          name: 'createdAt',
          type: 'date',
          interface: 'createdAt',
          description: null,
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          field: 'createdAt',
          uiSchema: {
            type: 'datetime',
            title: '{{t("Created at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: '6l38n4nt7nb',
          name: 'createdBy',
          type: 'belongsTo',
          interface: 'createdBy',
          description: null,
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'createdById',
          uiSchema: {
            type: 'object',
            title: '{{t("Created by")}}',
            'x-component': 'AssociationField',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
        {
          key: '3xds0p7ersr',
          name: 'updatedAt',
          type: 'date',
          interface: 'updatedAt',
          description: null,
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          field: 'updatedAt',
          uiSchema: {
            type: 'string',
            title: '{{t("Last updated at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: 'slqyx974mzc',
          name: 'updatedBy',
          type: 'belongsTo',
          interface: 'updatedBy',
          description: null,
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'updatedById',
          uiSchema: {
            type: 'object',
            title: '{{t("Last updated by")}}',
            'x-component': 'AssociationField',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
      ],
      category: [],
      logging: true,
      autoGenId: true,
      createdBy: true,
      updatedBy: true,
      createdAt: true,
      updatedAt: true,
      sortable: true,
      template: 'general',
      view: false,
      schema: 'public',
    },
  ],
};
export const builtin_Calendar = {
  collections: [
    {
      key: '7lfgblnyr0w',
      name: 'tt_amt_org_cld',
      title: '自动>组织[日历表]',
      inherit: false,
      hidden: false,
      description: null,
      fields: [
        {
          key: 'nq6a40fz0nd',
          name: 'cron',
          type: 'string',
          interface: 'select',
          description: null,
          collectionName: 'tt_amt_org_cld',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            title: '{{t("Repeats")}}',
            'x-component': 'CronSet',
            'x-component-props': 'allowClear',
            enum: [
              {
                label: '{{t("Daily")}}',
                value: '0 0 0 * * ?',
              },
              {
                label: '{{t("Weekly")}}',
                value: 'every_week',
              },
              {
                label: '{{t("Monthly")}}',
                value: 'every_month',
              },
              {
                label: '{{t("Yearly")}}',
                value: 'every_year',
              },
            ],
          },
        },
        {
          key: 'qtxt638o4nq',
          name: 'exclude',
          type: 'json',
          interface: null,
          description: null,
          collectionName: 'tt_amt_org_cld',
          parentKey: null,
          reverseKey: null,
        },
        {
          key: 'ly88an4fg8f',
          name: 'id',
          type: 'bigInt',
          interface: 'id',
          description: null,
          collectionName: 'tt_amt_org_cld',
          parentKey: null,
          reverseKey: null,
          autoIncrement: true,
          primaryKey: true,
          allowNull: false,
          uiSchema: {
            type: 'number',
            title: '{{t("ID")}}',
            'x-component': 'InputNumber',
            'x-read-pretty': true,
          },
        },
        {
          key: '8fiqtpovg79',
          name: 'createdAt',
          type: 'date',
          interface: 'createdAt',
          description: null,
          collectionName: 'tt_amt_org_cld',
          parentKey: null,
          reverseKey: null,
          field: 'createdAt',
          uiSchema: {
            type: 'datetime',
            title: '{{t("Created at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: 'hup33jdnp9j',
          name: 'createdBy',
          type: 'belongsTo',
          interface: 'createdBy',
          description: null,
          collectionName: 'tt_amt_org_cld',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'createdById',
          uiSchema: {
            type: 'object',
            title: '{{t("Created by")}}',
            'x-component': 'AssociationField',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
        {
          key: '4ky6wvfhduq',
          name: 'updatedAt',
          type: 'date',
          interface: 'updatedAt',
          description: null,
          collectionName: 'tt_amt_org_cld',
          parentKey: null,
          reverseKey: null,
          field: 'updatedAt',
          uiSchema: {
            type: 'string',
            title: '{{t("Last updated at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: '1xht59blk26',
          name: 'updatedBy',
          type: 'belongsTo',
          interface: 'updatedBy',
          description: null,
          collectionName: 'tt_amt_org_cld',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'updatedById',
          uiSchema: {
            type: 'object',
            title: '{{t("Last updated by")}}',
            'x-component': 'AssociationField',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
      ],
      category: [],
      logging: true,
      template: 'calendar',
      view: false,
      createdBy: true,
      updatedBy: true,
      createdAt: true,
      updatedAt: true,
      sortable: true,
      schema: 'public',
    },
  ],
};
export const builtin_Tree = {
  collections: [
    {
      key: 'wvgsufr1uxv',
      name: 'tt_amt_org_tree',
      title: '自动>组织[树表]',
      inherit: false,
      hidden: false,
      description: null,
      fields: [
        {
          key: '4ihc87rzn00',
          name: 'parentId',
          type: 'bigInt',
          interface: 'integer',
          description: null,
          collectionName: 'tt_amt_org_tree',
          parentKey: null,
          reverseKey: null,
          isForeignKey: true,
          uiSchema: {
            type: 'number',
            title: '{{t("Parent ID")}}',
            'x-component': 'InputNumber',
            'x-read-pretty': true,
          },
          target: 'tt_amt_org_tree',
        },
        {
          key: 'j58bfihyjdy',
          name: 'parent',
          type: 'belongsTo',
          interface: 'm2o',
          description: null,
          collectionName: 'tt_amt_org_tree',
          parentKey: null,
          reverseKey: null,
          foreignKey: 'parentId',
          treeParent: true,
          onDelete: 'CASCADE',
          uiSchema: {
            title: '{{t("Parent")}}',
            'x-component': 'AssociationField',
            'x-component-props': {
              multiple: false,
              fieldNames: {
                label: 'id',
                value: 'id',
              },
            },
          },
          target: 'tt_amt_org_tree',
          targetKey: 'id',
        },
        {
          key: '6r6b98g0hcz',
          name: 'children',
          type: 'hasMany',
          interface: 'o2m',
          description: null,
          collectionName: 'tt_amt_org_tree',
          parentKey: null,
          reverseKey: null,
          foreignKey: 'parentId',
          treeChildren: true,
          onDelete: 'CASCADE',
          uiSchema: {
            title: '{{t("Children")}}',
            'x-component': 'AssociationField',
            'x-component-props': {
              multiple: true,
              fieldNames: {
                label: 'id',
                value: 'id',
              },
            },
          },
          target: 'tt_amt_org_tree',
          targetKey: 'id',
          sourceKey: 'id',
        },
        {
          key: 'hju1ggqps4n',
          name: 'id',
          type: 'bigInt',
          interface: 'id',
          description: null,
          collectionName: 'tt_amt_org_tree',
          parentKey: null,
          reverseKey: null,
          autoIncrement: true,
          primaryKey: true,
          allowNull: false,
          uiSchema: {
            type: 'number',
            title: '{{t("ID")}}',
            'x-component': 'InputNumber',
            'x-read-pretty': true,
          },
        },
        {
          key: '1y7rpmh8muj',
          name: 'createdAt',
          type: 'date',
          interface: 'createdAt',
          description: null,
          collectionName: 'tt_amt_org_tree',
          parentKey: null,
          reverseKey: null,
          field: 'createdAt',
          uiSchema: {
            type: 'datetime',
            title: '{{t("Created at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: 'ieknujjdkv9',
          name: 'createdBy',
          type: 'belongsTo',
          interface: 'createdBy',
          description: null,
          collectionName: 'tt_amt_org_tree',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'createdById',
          uiSchema: {
            type: 'object',
            title: '{{t("Created by")}}',
            'x-component': 'AssociationField',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
        {
          key: 'cv35rzoqna6',
          name: 'updatedAt',
          type: 'date',
          interface: 'updatedAt',
          description: null,
          collectionName: 'tt_amt_org_tree',
          parentKey: null,
          reverseKey: null,
          field: 'updatedAt',
          uiSchema: {
            type: 'string',
            title: '{{t("Last updated at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: 'z21wfpry7uh',
          name: 'updatedBy',
          type: 'belongsTo',
          interface: 'updatedBy',
          description: null,
          collectionName: 'tt_amt_org_tree',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'updatedById',
          uiSchema: {
            type: 'object',
            title: '{{t("Last updated by")}}',
            'x-component': 'AssociationField',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
      ],
      category: [],
      logging: true,
      autoGenId: true,
      createdBy: true,
      updatedBy: true,
      createdAt: true,
      updatedAt: true,
      sortable: true,
      template: 'tree',
      view: false,
      tree: 'adjacencyList',
      schema: 'public',
    },
  ],
};
export const builtin_File = {
  collections: [
    {
      key: '6hzed4cvpxo',
      name: 'tt_amt_file',
      title: '自动>档案[文件表]',
      inherit: false,
      hidden: false,
      description: null,
      fields: [
        {
          key: 'qo0w8dcl45u',
          name: 'title',
          type: 'string',
          interface: 'input',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          deletable: false,
          uiSchema: {
            type: 'string',
            title: '{{t("Title")}}',
            'x-component': 'Input',
          },
        },
        {
          key: 'ayzc9b3aee5',
          name: 'filename',
          type: 'string',
          interface: 'input',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          deletable: false,
          uiSchema: {
            type: 'string',
            title: '{{t("File name", { ns: "file-manager" })}}',
            'x-component': 'Input',
            'x-read-pretty': true,
          },
        },
        {
          key: 'ftn60zv1rfr',
          name: 'extname',
          type: 'string',
          interface: 'input',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          deletable: false,
          uiSchema: {
            type: 'string',
            title: '{{t("Extension name", { ns: "file-manager" })}}',
            'x-component': 'Input',
            'x-read-pretty': true,
          },
        },
        {
          key: '59oj6m0r8be',
          name: 'size',
          type: 'integer',
          interface: 'integer',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          deletable: false,
          uiSchema: {
            type: 'number',
            title: '{{t("Size", { ns: "file-manager" })}}',
            'x-component': 'InputNumber',
            'x-read-pretty': true,
            'x-component-props': {
              stringMode: true,
              step: '0',
            },
          },
        },
        {
          key: 'burt1tfbcjx',
          name: 'mimetype',
          type: 'string',
          interface: 'input',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          deletable: false,
          uiSchema: {
            type: 'string',
            title: '{{t("Mime type", { ns: "file-manager" })}}',
            'x-component': 'Input',
            'x-read-pretty': true,
          },
        },
        {
          key: '1zfhbqod0i1',
          name: 'path',
          type: 'string',
          interface: 'input',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          deletable: false,
          uiSchema: {
            type: 'string',
            title: '{{t("Path")}}',
            'x-component': 'Input',
            'x-read-pretty': true,
          },
        },
        {
          key: 'b0bmsmrfqqw',
          name: 'url',
          type: 'string',
          interface: 'input',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          deletable: false,
          uiSchema: {
            type: 'string',
            title: '{{t("URL")}}',
            'x-component': 'Input.URL',
            'x-read-pretty': true,
          },
        },
        {
          key: 'indgsp9sqqq',
          name: 'preview',
          type: 'string',
          interface: 'url',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          field: 'url',
          deletable: false,
          uiSchema: {
            type: 'string',
            title: '{{t("Preview")}}',
            'x-component': 'Preview',
            'x-read-pretty': true,
          },
        },
        {
          key: '2p8d1h46x9l',
          name: 'storage',
          type: 'belongsTo',
          interface: null,
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          comment: '存储引擎',
          target: 'storages',
          foreignKey: 'storageId',
          deletable: false,
          targetKey: 'id',
        },
        {
          key: 'im0yegvb5jt',
          name: 'meta',
          type: 'jsonb',
          interface: null,
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          deletable: false,
          defaultValue: {},
        },
        {
          key: 'tjr9nr5thoh',
          name: 'id',
          type: 'bigInt',
          interface: 'id',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          autoIncrement: true,
          primaryKey: true,
          allowNull: false,
          uiSchema: {
            type: 'number',
            title: '{{t("ID")}}',
            'x-component': 'InputNumber',
            'x-read-pretty': true,
          },
        },
        {
          key: 's48vjiqbjcq',
          name: 'createdAt',
          type: 'date',
          interface: 'createdAt',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          field: 'createdAt',
          uiSchema: {
            type: 'datetime',
            title: '{{t("Created at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: 'y3t7jii4m8w',
          name: 'createdBy',
          type: 'belongsTo',
          interface: 'createdBy',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'createdById',
          uiSchema: {
            type: 'object',
            title: '{{t("Created by")}}',
            'x-component': 'RecordPicker',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
        {
          key: 'z5gvejdbfyb',
          name: 'updatedAt',
          type: 'date',
          interface: 'updatedAt',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          field: 'updatedAt',
          uiSchema: {
            type: 'string',
            title: '{{t("Last updated at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: 'qgd8zko7b0z',
          name: 'updatedBy',
          type: 'belongsTo',
          interface: 'updatedBy',
          description: null,
          collectionName: 'tt_amt_file',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'updatedById',
          uiSchema: {
            type: 'object',
            title: '{{t("Last updated by")}}',
            'x-component': 'RecordPicker',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
      ],
      category: [],
      logging: true,
      template: 'file',
      view: false,
      createdBy: true,
      updatedBy: true,
      storage: 'local',
      schema: 'public',
    },
  ],
};
export const builtin_Expression = {
  collections: [
    {
      key: 'w77iro3197g',
      name: 'tt_amt_exp',
      title: '自动>表达式[表达式表]',
      inherit: false,
      hidden: false,
      description: null,
      fields: [
        {
          key: 'slc2i7yz2ck',
          name: 'engine',
          type: 'string',
          interface: 'radioGroup',
          description: null,
          collectionName: 'tt_amt_exp',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            title: '{{t("Calculation engine")}}',
            'x-component': 'Radio.Group',
            enum: [
              {
                value: 'math.js',
                label: 'Math.js',
                tooltip:
                  "{{t('Math.js comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types')}}",
                link: 'https://mathjs.org/',
              },
              {
                value: 'formula.js',
                label: 'Formula.js',
                tooltip: '{{t("Formula.js supports most Microsoft Excel formula functions.")}}',
                link: 'https://formulajs.info/functions/',
              },
            ],
            default: 'formula.js',
          },
        },
        {
          key: 'mlvkdcg2yvq',
          name: 'sourceCollection',
          type: 'string',
          interface: 'select',
          description: null,
          collectionName: 'tt_amt_exp',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            title: '{{t("Collection")}}',
            'x-component': 'CollectionSelect',
            'x-component-props': {},
          },
        },
        {
          key: 'vdzigakt9ne',
          name: 'expression',
          type: 'text',
          interface: 'expression',
          description: null,
          collectionName: 'tt_amt_exp',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            title: '{{t("Expression")}}',
            'x-component': 'DynamicExpression',
          },
        },
        {
          key: 'fx72pqt0fjv',
          name: 'id',
          type: 'bigInt',
          interface: 'id',
          description: null,
          collectionName: 'tt_amt_exp',
          parentKey: null,
          reverseKey: null,
          autoIncrement: true,
          primaryKey: true,
          allowNull: false,
          uiSchema: {
            type: 'number',
            title: '{{t("ID")}}',
            'x-component': 'InputNumber',
            'x-read-pretty': true,
          },
        },
        {
          key: 'owiio66cw1u',
          name: 'createdAt',
          type: 'date',
          interface: 'createdAt',
          description: null,
          collectionName: 'tt_amt_exp',
          parentKey: null,
          reverseKey: null,
          field: 'createdAt',
          uiSchema: {
            type: 'datetime',
            title: '{{t("Created at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: '9fu8kmc69dj',
          name: 'createdBy',
          type: 'belongsTo',
          interface: 'createdBy',
          description: null,
          collectionName: 'tt_amt_exp',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'createdById',
          uiSchema: {
            type: 'object',
            title: '{{t("Created by")}}',
            'x-component': 'RecordPicker',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
        {
          key: 'uie8q16z2jj',
          name: 'updatedAt',
          type: 'date',
          interface: 'updatedAt',
          description: null,
          collectionName: 'tt_amt_exp',
          parentKey: null,
          reverseKey: null,
          field: 'updatedAt',
          uiSchema: {
            type: 'string',
            title: '{{t("Last updated at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: '6jzyuc1jzro',
          name: 'updatedBy',
          type: 'belongsTo',
          interface: 'updatedBy',
          description: null,
          collectionName: 'tt_amt_exp',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'updatedById',
          uiSchema: {
            type: 'object',
            title: '{{t("Last updated by")}}',
            'x-component': 'RecordPicker',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
      ],
      category: [],
      logging: true,
      template: 'expression',
      view: false,
      createdBy: true,
      updatedBy: true,
      createdAt: true,
      updatedAt: true,
      sortable: true,
      schema: 'public',
    },
  ],
};
//普通表单表场景，无关系字段情况
export const e2e_GeneralFormsTable = {
  collections: [
    {
      key: '86lpobjxamt',
      name: 'tt_amt_org',
      title: '自动>组织[普通表]',
      inherit: false,
      hidden: false,
      fields: [
        {
          key: 'ohxa8xp9amt',
          name: 'id',
          type: 'bigInt',
          interface: 'id',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          autoIncrement: true,
          primaryKey: true,
          allowNull: false,
          uiSchema: {
            type: 'number',
            title: '{{t("ID")}}',
            'x-component': 'InputNumber',
            'x-read-pretty': true,
          },
        },
        {
          key: 'qjit9pcvamt',
          name: 'createdAt',
          type: 'date',
          interface: 'createdAt',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          field: 'createdAt',
          uiSchema: {
            type: 'datetime',
            title: '{{t("Created at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: 'vijs3wcnamt',
          name: 'createdBy',
          type: 'belongsTo',
          interface: 'createdBy',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'createdById',
          uiSchema: {
            type: 'object',
            title: '{{t("Created by")}}',
            'x-component': 'AssociationField',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
        {
          key: 'zsebjtwiamt',
          name: 'updatedAt',
          type: 'date',
          interface: 'updatedAt',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          field: 'updatedAt',
          uiSchema: {
            type: 'string',
            title: '{{t("Last updated at")}}',
            'x-component': 'DatePicker',
            'x-component-props': {},
            'x-read-pretty': true,
          },
        },
        {
          key: 'fa4c74phamt',
          name: 'updatedBy',
          type: 'belongsTo',
          interface: 'updatedBy',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          target: 'users',
          foreignKey: 'updatedById',
          uiSchema: {
            type: 'object',
            title: '{{t("Last updated by")}}',
            'x-component': 'AssociationField',
            'x-component-props': {
              fieldNames: {
                value: 'id',
                label: 'nickname',
              },
            },
            'x-read-pretty': true,
          },
          targetKey: 'id',
        },
        {
          key: 'mv6h7f8lamt',
          name: 'orgcode',
          type: 'sequence',
          interface: 'sequence',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          patterns: [
            {
              type: 'string',
              options: {
                value: '区域编码',
              },
            },
            {
              type: 'integer',
              options: {
                digits: 9,
                start: 1,
                key: 57450,
              },
            },
          ],
          uiSchema: {
            type: 'string',
            'x-component': 'Input',
            'x-component-props': {},
            title: '公司编号(自动编码)',
          },
          inputable: false,
        },
        {
          key: '44u5zoyyamt',
          name: 'orgname',
          type: 'string',
          interface: 'input',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            'x-component': 'Input',
            title: '公司名称(单行文本)',
          },
        },
        {
          key: 'tdq82bb0amt',
          name: 'address',
          type: 'text',
          interface: 'textarea',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            'x-component': 'Input.TextArea',
            title: '公司地址(多行文本)',
          },
        },
        {
          key: '10xi6i24amt',
          name: 'phone',
          type: 'string',
          interface: 'phone',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            'x-component': 'Input',
            'x-component-props': {
              type: 'tel',
            },
            title: '负责人电话(手机号码)',
          },
        },
        {
          key: 'n3ykqhe4amt',
          name: 'email',
          type: 'string',
          interface: 'email',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            'x-component': 'Input',
            'x-validator': 'email',
            title: '电子邮箱(电子邮箱)',
          },
        },
        {
          key: '5ddcgbpqamt',
          name: 'staffnum',
          type: 'bigInt',
          interface: 'integer',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'number',
            'x-component': 'InputNumber',
            'x-component-props': {
              stringMode: true,
              step: '1',
            },
            'x-validator': 'integer',
            title: '员工人数(整数)',
          },
        },
        {
          key: 'z59sf4ilamt',
          name: 'insurednum',
          type: 'bigInt',
          interface: 'integer',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'number',
            'x-component': 'InputNumber',
            'x-component-props': {
              stringMode: true,
              step: '1',
            },
            'x-validator': 'integer',
            title: '参保人数(整数)',
          },
        },
        {
          key: 'ecvb3a8xamt',
          name: 'regcapital',
          type: 'double',
          interface: 'number',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            'x-component-props': {
              step: '0.0001',
              stringMode: true,
            },
            type: 'number',
            'x-component': 'InputNumber',
            title: '注册资本(数字)',
          },
        },
        {
          key: 'ierg1fbvamt',
          name: 'paidcapital',
          type: 'double',
          interface: 'number',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            'x-component-props': {
              step: '0.0001',
              stringMode: true,
            },
            type: 'number',
            'x-component': 'InputNumber',
            title: '实缴资本(数字)',
          },
        },
        {
          key: '46kjnywaamt',
          name: 'insuranceratio',
          type: 'float',
          interface: 'percent',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            'x-component-props': {
              step: '0.01',
              stringMode: true,
              addonAfter: '%',
            },
            type: 'string',
            'x-component': 'Percent',
            title: '参保占比(百分比)',
          },
        },
        {
          key: '8j2vkys9amt',
          name: 'isenable',
          type: 'boolean',
          interface: 'checkbox',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'boolean',
            'x-component': 'Checkbox',
            title: '是否启用(勾选)',
          },
        },
        {
          key: '6f480de5amt',
          name: 'status_singleselect',
          type: 'string',
          interface: 'select',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            enum: [
              {
                value: '1',
                label: '存续',
              },
              {
                value: '2',
                label: '在业',
              },
              {
                value: '3',
                label: '吊销',
              },
              {
                value: '4',
                label: '注销',
              },
              {
                value: '5',
                label: '迁入',
              },
              {
                value: '6',
                label: '迁出',
              },
              {
                value: '7',
                label: '停业',
              },
              {
                value: '8',
                label: '清算',
              },
            ],
            type: 'string',
            'x-component': 'Select',
            title: '公司状态(下拉单选)',
          },
        },
        {
          key: 'fcx8cw1ramt',
          name: 'range_multipleselect',
          type: 'array',
          interface: 'multipleSelect',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            enum: [
              {
                value: 'F3134',
                label: '软件销售',
              },
              {
                value: 'I3006',
                label: '软件开发',
              },
              {
                value: 'I3007',
                label: '人工智能基础软件开发',
              },
              {
                value: 'I3008',
                label: '人工智能应用软件开发',
              },
              {
                value: 'I3010',
                label: '软件外包服务',
              },
              {
                value: 'I3011',
                label: '网络与信息安全软件开发',
              },
              {
                value: 'I3012',
                label: '人工智能理论与算法软件开发',
              },
              {
                value: 'I3014',
                label: '数字文化创意软件开发',
              },
              {
                value: 'I3027',
                label: '信息技术咨询服务',
              },
              {
                value: 'I3032',
                label: '数据处理服务',
              },
              {
                value: 'I3034',
                label: '计算机系统服务',
              },
              {
                value: 'L2032',
                label: '信息咨询服务（不含许可类信息咨询服务）',
              },
              {
                value: 'L2095',
                label: '企业管理咨询',
              },
              {
                value: 'M2070',
                label: '技术服务、技术开发、技术咨询、技术交流、技术转让、技术推广',
              },
              {
                value: 'O3010',
                label: '咨询策划服务',
              },
              {
                value: 'P1029',
                label: '业务培训（不含教育培训、职业技能培训等需取得许可的培训）',
              },
            ],
            type: 'array',
            'x-component': 'Select',
            'x-component-props': {
              mode: 'multiple',
            },
            title: '经营范围(下拉多选)',
          },
          defaultValue: [],
        },
        {
          key: 'z71al7aaamt',
          name: 'status_radio',
          type: 'string',
          interface: 'radioGroup',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            enum: [
              {
                value: '1',
                label: '存续',
              },
              {
                value: '2',
                label: '在业',
              },
              {
                value: '3',
                label: '吊销',
              },
              {
                value: '4',
                label: '注销',
              },
              {
                value: '5',
                label: '迁入',
              },
              {
                value: '6',
                label: '迁出',
              },
              {
                value: '7',
                label: '停业',
              },
              {
                value: '8',
                label: '清算',
              },
            ],
            type: 'string',
            'x-component': 'Radio.Group',
            title: '公司状态(单选)',
          },
        },
        {
          key: 'x8v9qf95amt',
          name: 'range_check',
          type: 'array',
          interface: 'checkboxGroup',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            enum: [
              {
                value: 'F3134',
                label: '软件销售',
              },
              {
                value: 'I3006',
                label: '软件开发',
              },
              {
                value: 'I3007',
                label: '人工智能基础软件开发',
              },
              {
                value: 'I3008',
                label: '人工智能应用软件开发',
              },
              {
                value: 'I3010',
                label: '软件外包服务',
              },
              {
                value: 'I3011',
                label: '网络与信息安全软件开发',
              },
              {
                value: 'I3012',
                label: '人工智能理论与算法软件开发',
              },
              {
                value: 'I3014',
                label: '数字文化创意软件开发',
              },
              {
                value: 'I3027',
                label: '信息技术咨询服务',
              },
              {
                value: 'I3032',
                label: '数据处理服务',
              },
              {
                value: 'I3034',
                label: '计算机系统服务',
              },
              {
                value: 'L2032',
                label: '信息咨询服务（不含许可类信息咨询服务）',
              },
              {
                value: 'L2095',
                label: '企业管理咨询',
              },
              {
                value: 'M2070',
                label: '技术服务、技术开发、技术咨询、技术交流、技术转让、技术推广',
              },
              {
                value: 'O3010',
                label: '咨询策划服务',
              },
              {
                value: 'P1029',
                label: '业务培训（不含教育培训、职业技能培训等需取得许可的培训）',
              },
            ],
            type: 'string',
            'x-component': 'Checkbox.Group',
            title: '经营范围(复选)',
          },
          defaultValue: [],
        },
        {
          key: 'c50l1zguamt',
          name: 'range_markdown',
          type: 'text',
          interface: 'markdown',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            'x-component': 'Markdown',
            title: '经营范围(Markdown)',
          },
        },
        {
          key: 'msj1qa4damt',
          name: 'range_richtext',
          type: 'text',
          interface: 'richText',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            'x-component': 'RichText',
            title: '经营范围(富文本)',
          },
        },
        {
          key: 'q755hkxmamt',
          name: 'establishdate',
          type: 'date',
          interface: 'datetime',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            'x-component-props': {
              dateFormat: 'YYYY-MM-DD',
              gmt: false,
              showTime: false,
            },
            type: 'string',
            'x-component': 'DatePicker',
            title: '成立日期(日期)',
          },
        },
        {
          key: '9kn4ujeramt',
          name: 'range_json',
          type: 'json',
          interface: 'json',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          defaultValue: null,
          uiSchema: {
            type: 'object',
            'x-component': 'Input.JSON',
            'x-component-props': {
              autoSize: {
                minRows: 5,
              },
            },
            default: null,
            title: '经营范围(JSON)',
          },
        },
        {
          key: 'vqcsj7htamt',
          name: 'url',
          type: 'string',
          interface: 'url',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'string',
            title: '官网地址(URL)',
            'x-component': 'Input.URL',
          },
        },
        {
          key: '0naiw2nq4j0',
          name: 'insuranceratio_formula',
          type: 'formula',
          interface: 'formula',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          dataType: 'double',
          uiSchema: {
            'x-component-props': {
              step: '0.01',
              stringMode: true,
            },
            type: 'number',
            'x-component': 'Formula.Result',
            'x-read-pretty': true,
            title: '参保占比(公式)',
          },
          engine: 'math.js',
          expression: '100*{{insurednum}}/{{staffnum}}',
        },
        {
          key: 'fd9sqp8usoj',
          name: 'sharesnum',
          type: 'bigInt',
          interface: 'integer',
          collectionName: 'tt_amt_org',
          parentKey: null,
          reverseKey: null,
          uiSchema: {
            type: 'number',
            'x-component': 'InputNumber',
            'x-component-props': {
              stringMode: true,
              step: '1',
            },
            'x-validator': 'integer',
            title: '股票数量(整数)',
          },
        },
      ],
      category: [],
      logging: true,
      autoGenId: true,
      createdBy: true,
      updatedBy: true,
      createdAt: true,
      updatedAt: true,
      sortable: true,
      template: 'general',
    },
  ],
};

export default module.exports = {
  appendJsonCollectionName,
  builtin_General,
  builtin_File,
  builtin_Expression,
  e2e_GeneralFormsTable,
  generateRandomLetters,
};
