import type {
  ProColumns,
  ProDescriptionsItemProps,
} from '@ant-design/pro-components';
import { Space, Tag } from 'antd';
import dayjs from 'dayjs';
import type { SmsLogVO } from '@/services/system/message/sms/log';
export const baseTenantColumns: ProColumns<SmsLogVO>[] = [
  {
    title: '编号',
    dataIndex: 'id',
    width: 100,
    hideInSearch: true, // 在搜索表单中隐藏
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    valueType: 'dateRange',
    hideInSearch: true,
    search: {
      transform: (value) => {
        return {
          [`createTime[0]`]: dayjs(value[0])
            .startOf('day')
            .format('YYYY-MM-DD HH:mm:ss'),
          [`createTime[1]`]: dayjs(value[1])
            .endOf('day')
            .format('YYYY-MM-DD HH:mm:ss'),
        };
      },
    },
    render: (_, record: SmsLogVO) =>
      dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'),
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
  },
  {
    title: '短信内容',
    dataIndex: 'templateContent',
    hideInSearch: true, // 在搜索表单中隐藏
  },
  {
    title: '发送状态',
    dataIndex: 'sendStatus',
  },

  {
    title: '接收状态',
    dataIndex: 'receiveStatus',
  },
  {
    title: '短信渠道',
    dataIndex: 'channelId',
  },
  {
    title: '模板编号',
    dataIndex: 'templateId',
  },
  {
    title: '短信类型',
    dataIndex: 'templateType',
    hideInSearch: true,
  },
  {
    title: '发送时间',
    dataIndex: 'sendTime',
    valueType: 'dateRange',
    hideInTable: true,
    search: {
      transform: (value) => {
        return {
          [`createTime[0]`]: dayjs(value[0])
            .startOf('day')
            .format('YYYY-MM-DD HH:mm:ss'),
          [`createTime[1]`]: dayjs(value[1])
            .endOf('day')
            .format('YYYY-MM-DD HH:mm:ss'),
        };
      },
    },
    render: (_, record: SmsLogVO) =>
      dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'),
  },
  {
    title: '接收时间',
    dataIndex: 'receiveTime',
    valueType: 'dateRange',
    hideInTable: true,
    search: {
      transform: (value) => {
        return {
          [`createTime[0]`]: dayjs(value[0])
            .startOf('day')
            .format('YYYY-MM-DD HH:mm:ss'),
          [`createTime[1]`]: dayjs(value[1])
            .endOf('day')
            .format('YYYY-MM-DD HH:mm:ss'),
        };
      },
    },
    render: (_, record: SmsLogVO) =>
      dayjs(record.createTime).format('YYYY-MM-DD HH:mm:ss'),
  },
];

export const descriptionsColumns = (): ProDescriptionsItemProps<
  Record<string, any>,
  'text'
>[] => [
  {
    title: '日志主键',
    key: 'id',
    dataIndex: 'id',
  },
  {
    title: '短信渠道',
    key: 'channelId',
    dataIndex: 'channelId',
  },
  {
    title: '短信模板',
    key: 'templateCode',
    dataIndex: 'templateCode',
  },
  {
    title: 'API 的模板编号',
    key: 'apiTemplateId',
    dataIndex: 'apiTemplateId',
  },
  {
    title: '用户信息',
    key: 'mobile',
    dataIndex: 'mobile',
    render(dom, record) {
      return (
        <>
          <Space>
            <Tag>{record.mobile}</Tag>
            {record.userId && <Tag>{record.userId}</Tag>}
          </Space>
        </>
      );
    },
  },
  {
    title: '短信内容',
    key: 'templateContent',
    dataIndex: 'templateContent',
  },
  {
    title: '短信参数',
    key: 'templateParams',
    dataIndex: 'templateParams',
  },
  {
    title: '创建时间',
    key: 'createTime',
    dataIndex: 'createTime',
  },
  {
    title: '发送状态',
    key: 'sendStatus',
    dataIndex: 'sendStatus',
  },
  {
    title: '发送时间',
    key: 'sendTime',
    dataIndex: 'sendTime',
  },
  {
    title: 'API 发送结果',
    key: 'apiSendMsg',
    dataIndex: 'apiSendMsg',
  },
  {
    title: 'API 短信编号',
    key: 'apiSerialNo',
    dataIndex: 'apiSerialNo',
  },
  {
    title: 'API 请求编号',
    key: 'apiRequestId',
    dataIndex: 'apiRequestId',
  },
  {
    title: 'API 接收状态',
    key: 'receiveStatus',
    dataIndex: 'receiveStatus',
  },
  {
    title: 'API 接收结果',
    key: 'apiReceiveMsg',
    dataIndex: 'apiReceiveMsg',
  },
];
