/**
 * ERP API 配置管理 - 数据定义
 */
import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

/**
 * 搜索表单 Schema
 */
export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'apiName',
    label: 'API名称',
    componentProps: {
      placeholder: '请输入API名称',
      allowClear: true,
    },
  },
  {
    component: 'Input',
    fieldName: 'apiPath',
    label: 'API路径',
    componentProps: {
      placeholder: '请输入API路径',
      allowClear: true,
    },
  },
  {
    component: 'Select',
    fieldName: 'apiMethod',
    label: 'HTTP方法',
    componentProps: {
      placeholder: '请选择HTTP方法',
      options: [
        { label: 'GET', value: 'GET' },
        { label: 'POST', value: 'POST' },
      ],
      allowClear: true,
    },
  },
  {
    component: 'Select',
    fieldName: 'status',
    label: '状态',
    componentProps: {
      placeholder: '请选择状态',
      options: [
        { label: '启用', value: '1' },
        { label: '禁用', value: '0' },
      ],
      allowClear: true,
    },
  },
];

/**
 * 表格列定义
 */
export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    field: 'apiName',
    title: 'API名称',
    minWidth: 150,
    showOverflow: 'tooltip',
  },
  {
    field: 'apiPath',
    title: 'API路径',
    minWidth: 200,
    showOverflow: 'tooltip',
  },
  {
    field: 'apiMethod',
    title: 'HTTP方法',
    width: 100,
  },
  {
    field: 'apiVersion',
    title: '版本',
    width: 80,
  },
  {
    field: 'resultType',
    title: '结果类型',
    width: 100,
  },
  {
    field: 'supportPagination',
    title: '分页',
    width: 80,
    slots: { default: 'pagination' },
  },
  {
    field: 'requireAuth',
    title: '认证',
    width: 80,
    slots: { default: 'auth' },
  },
  {
    field: 'enableCache',
    title: '缓存',
    width: 80,
    slots: { default: 'cache' },
  },
  {
    field: 'status',
    title: '状态',
    width: 100,
    slots: { default: 'status' },
  },
  {
    field: 'createTime',
    title: '创建时间',
    width: 150,
    formatter: 'formatDateTime',
  },
  {
    field: 'action',
    title: '操作',
    width: 250,
    fixed: 'right',
    slots: { default: 'action' },
  },
];

/**
 * API方法选项
 */
export const apiMethodOptions = [
  { label: 'GET', value: 'GET' },
  { label: 'POST', value: 'POST' },
];

/**
 * API版本选项
 */
export const apiVersionOptions = [
  { label: 'v1', value: 'v1' },
  { label: 'v2', value: 'v2' },
];

/**
 * 结果类型选项
 */
export const resultTypeOptions = [
  { label: '列表', value: 'LIST' },
  { label: '单条', value: 'SINGLE' },
  { label: '计数', value: 'COUNT' },
];

/**
 * 参数类型选项
 */
export const paramTypeOptions = [
  { label: 'String', value: 'String' },
  { label: 'Integer', value: 'Integer' },
  { label: 'Long', value: 'Long' },
  { label: 'Double', value: 'Double' },
  { label: 'Date', value: 'Date' },
  { label: 'DateTime', value: 'DateTime' },
  { label: 'Boolean', value: 'Boolean' },
];

/**
 * 参数位置选项
 */
export const paramPositionOptions = [
  { label: 'QUERY', value: 'QUERY' },
  { label: 'BODY', value: 'BODY' },
];

/**
 * 数据源选项（待扩展）
 */
export const dataSourceOptions = [
  { label: 'ERP数据源', value: 'erp' },
];

/**
 * 参数配置表格列定义
 */
export const paramColumns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    field: 'paramName',
    title: '参数名称',
    minWidth: 150,
    editRender: { name: 'input' },
  },
  {
    field: 'paramType',
    title: '参数类型',
    width: 120,
    editRender: {
      name: 'select',
      options: paramTypeOptions,
    },
  },
  {
    field: 'paramPosition',
    title: '参数位置',
    width: 100,
    editRender: {
      name: 'select',
      options: paramPositionOptions,
    },
  },
  {
    field: 'isRequired',
    title: '必填',
    width: 80,
    editRender: { name: 'checkbox' },
  },
  {
    field: 'defaultValue',
    title: '默认值',
    minWidth: 120,
    editRender: { name: 'input' },
  },
  {
    field: 'paramDesc',
    title: '参数描述',
    minWidth: 200,
    editRender: { name: 'input' },
  },
  {
    field: 'sort',
    title: '排序',
    width: 80,
    editRender: { name: 'input', attrs: { type: 'number' } },
  },
  {
    field: 'action',
    title: '操作',
    width: 100,
    slots: { default: 'paramAction' },
  },
];