import type { VxeGridProps } from '#/adapter/vxe-table';

import { getOaNotifyLogList } from '#/views/system/oa-notify-log/api';

interface RowType {
  id: number;
  scene_id: number;
  scene_code: string;
  robot_id: number;
  platform_code: string;
  message_type: string;
  send_type: string;
  request_payload: string;
  response_payload: string;
  status: number;
  error_msg: string;
  cost_ms: number;
  created_at: string;
}

/**
 * 日志列表表格配置（只读，无操作列）
 */
export const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: '',
  },
  columnConfig: {
    useKey: true,
  },
  rowConfig: {
    useKey: true,
  },
  columns: [
    { type: 'checkbox', width: 60 },
    { field: 'id', align: 'left', title: 'ID', width: 100 },
    { field: 'scene_code', align: 'left', title: '场景编码', width: 180 },
    { field: 'platform_code', align: 'left', title: '平台', width: 120, slots: { default: 'platform_code' } },
    { field: 'robot_id', align: 'left', title: '机器人ID', width: 100 },
    { field: 'message_type', align: 'left', title: '消息类型', width: 100, slots: { default: 'message_type' } },
    { field: 'send_type', align: 'left', title: '发送类型', width: 100, slots: { default: 'send_type' } },
    { field: 'request_payload', align: 'left', title: '请求体', slots: { default: 'request_payload' } },
    { field: 'status', align: 'left', title: '状态', width: 100, slots: { default: 'status' } },
    { field: 'error_msg', align: 'left', title: '错误信息', slots: { default: 'error_msg' } },
    { field: 'cost_ms', align: 'left', title: '耗时(ms)', width: 100 },
    { field: 'created_at', align: 'left', title: '发送时间', width: 180 },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getOaNotifyLogList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  height: 'auto',
  border: false,
  toolbarConfig: {
    search: true,
    refresh: true,
    print: false,
    export: false,
    zoom: true,
    slots: {
      buttons: 'toolbar-actions',
    },
    custom: {
      icon: 'vxe-icon-menu',
    },
  },
  showOverflow: false,
};
