import { BasicColumn, FormSchema } from '/@/components/Table';
import type { FormSchema as QFormSchema } from '/@/components/Form/index';
import { JCronValidator } from '/@/components/Form';
import { EJobGroup } from './config.data';

// 定时任务表格配置
export const columnSchedue: BasicColumn[] = [
  {
    title: '任务名称',
    dataIndex: 'jobName',
    width: 120,
  },
  {
    title: '任务组名',
    dataIndex: 'jobGroup',
    width: 120,
    format: (_text: string, record: Recordable) => {
      return record.jobGroup === EJobGroup.DEFAULT
        ? '默认'
        : record.jobGroup === EJobGroup.SYSTEM
        ? '系统'
        : '报表';
    },
  },
  {
    title: '调用目标字符串',
    dataIndex: 'invokeTarget',
    width: 120,
  },
  {
    title: 'cron执行表达式',
    dataIndex: 'cronExpression',
    width: 160,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 160,
    slots: { customRender: 'status' },
  },
];

// 定时任务格查询配置
export const searchSchedueFormSchema: FormSchema[] = [
  {
    field: 'jobName',
    label: '任务名称',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 36,
      placeholder: '请输入任务名称',
    },
  },
  {
    field: 'jobGroup',
    label: '任务组名',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        {
          label: '默认',
          value: EJobGroup.DEFAULT,
        },
        {
          label: '系统',
          value: EJobGroup.SYSTEM,
        },
        {
          label: '报表',
          value: EJobGroup.REPORT,
        },
      ],
      placeholder: '请选择任务组名',
    },
  },
  {
    field: 'status',
    label: '任务状态',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        {
          label: '启用',
          value: 1,
        },
        {
          label: '禁用',
          value: 0,
        },
      ],
      placeholder: '请选择任务状态',
    },
  },
];

// 新增编辑配置
export const formSchema: QFormSchema[] = [
  {
    field: 'jobName',
    label: '任务名称',
    colProps: { span: 24 },
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入任务名称',
    },
  },
  {
    field: 'jobGroup',
    component: 'Select',
    label: '任务分组',
    colProps: {
      span: 24,
    },
    componentProps: {
      placeholder: '请选择任务分组',
      options: [
        {
          label: '默认',
          value: EJobGroup.DEFAULT,
        },
        {
          label: '系统',
          value: EJobGroup.SYSTEM,
        },
        {
          label: '报表',
          value: EJobGroup.REPORT,
        },
      ],
    },
  },
  {
    field: 'invokeTarget',
    label: ' 调用方法',
    helpMessage: [
      'Bean调用示例：reportTask.noParams()Class类调用示例：reportTask.noParams()参数说明：支持字符串，布尔类型，长整型，浮点型，整型',
    ],
    colProps: { span: 24 },
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入调用方法',
    },
  },
  {
    field: 'cronExpression',
    label: 'Cron表达式',
    component: 'JEasyCron',
    defaultValue: '* * * * * ? *',
    colProps: {
      span: 24,
    },
    rules: [{ required: true, message: '请输入Cron表达式' }, { validator: JCronValidator }],
  },
  {
    field: 'misfirePolicy',
    component: 'RadioButtonGroup',
    label: '执行策略',
    colProps: {
      span: 24,
    },
    defaultValue: 1,
    componentProps: {
      options: [
        {
          label: '立即执行',
          value: 0,
        },
        {
          label: '执行一次',
          value: 1,
        },
        {
          label: '放弃执行',
          value: 2,
        },
      ],
    },
  },
  {
    field: 'concurrent',
    component: 'RadioButtonGroup',
    label: '是否并发',
    colProps: {
      span: 24,
    },
    defaultValue: 1,
    componentProps: {
      options: [
        {
          label: '允许',
          value: 0,
        },
        {
          label: '禁止',
          value: 1,
        },
      ],
    },
  },
  {
    field: 'status',
    component: 'RadioGroup',
    label: '状态',
    colProps: {
      span: 24,
    },
    defaultValue: 1,
    componentProps: {
      options: [
        {
          label: '启用',
          value: 1,
        },
        {
          label: '禁用',
          value: 0,
        },
      ],
    },
  },
];
