import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { findDictItemByCode } from '/@/api/system/dict';
import { MessageEnum } from '/@/enums/messageEnum';
export const columns: BasicColumn[] = [
  {
    title: '配置名称',
    dataIndex: 'configName',
    width: 200,
  },
  {
    title: '消息类型',
    dataIndex: 'messageTypeDictText',
    width: 200,
  },
  {
    title: '平台类型',
    dataIndex: 'platformTypeDictText',
    width: 180,
  },
  {
    title: '配置信息',
    dataIndex: 'config',
    width: 180,
    slots: { customRender: 'config' },
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 120,
    slots: { customRender: 'status' },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'messageType',
    label: '消息类型',
    component: 'ApiSelect',
    colProps: {
      span: 6,
    },
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'message_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        { label: '已启用', value: 1 },
        { label: '已禁用', value: 0 },
      ],
    },
  },
];

export const isMessage = (type: string) => {
  return type === MessageEnum.IS_SMS;
};
export const isEmail = (type: string) => {
  return type === MessageEnum.IS_EMAIL;
};

export const formSchema: FormSchema[] = [
  {
    field: 'configName',
    label: '配置名称',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 30,
      placeholder: '请输入配置名称',
    },
  },
  {
    field: 'messageType',
    label: '消息类型',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'message_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
  {
    field: 'platformType',
    label: '平台类型',
    required: true,
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'platform_type',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'accessKeyId',
    label: 'accessKeyId',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 36,
      placeholder: '请输入accessKeyId',
    },
    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'accessKeySecret',
    label: 'accessKeySecret',
    required: true,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入accessKeySecret',
    },

    component: 'Input',
    ifShow: ({ values }) => isMessage(Reflect.get(values, 'messageType')),
  },
  {
    field: 'host',
    label: '服务器地址',
    defaultValue: 'smtp.163.com',
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 36,
      placeholder: '请输入服务器地址',
    },

    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'port',
    label: '端口',
    defaultValue: 25,
    required: true,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入端口',
    },

    component: 'InputNumber',
    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'username',
    label: '用户名',
    required: true,
    componentProps: {
      maxLength: 255,
      placeholder: '请输入用户名',
    },
    component: 'Input',
    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'password',
    label: '密码',
    required: true,
    component: 'InputPassword',
    ifShow: ({ values }) => isEmail(Reflect.get(values, 'messageType')),
  },
  {
    field: 'config',
    label: '消息配置',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 255,
      placeholder: '请输入消息配置',
    },
  },
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入主键',
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '启用', value: 1 },
        { label: '停用', value: 0 },
      ],
    },
  },
  {
    label: '备注',
    field: 'remark',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入备注',
    },
    component: 'InputTextArea',
  },
  {
    label: '租户ID',
    field: 'tenantId',
    component: 'Input',
    show: false,
    componentProps: {
      maxLength: 36,
      placeholder: '请输入租户ID',
    },
  },
];
