/**
 * 项目：-
 * 模型分组：系统管理
 * 模型名称：用户角色关系表
 * @Author: xiongwei
 * @Date: 2022-06-28 11:50:00
 */

import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import get from 'lodash.get';


const colProps = { xs: { span: 24 }, sm: { span: 24 }, lg: { span: 8 } };
const colPropsInDrawer = { span: 24 };

export const schema = {
  model: 'UserRole',
  viewInPage: false,
  properties: [
    {
      field: 'id',
      label: 'ID系统自动生成',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: 'ID系统自动生成',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入ID系统自动生成！' }],
      },
      table: {
      },
    },
    {
      field: 'userId',
      label: '用户ID',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: '用户ID',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入用户ID！' }],
      },
      table: {
      },
    },
    {
      field: 'roleId',
      label: '角色ID',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: '角色ID',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入角色ID！' }],
      },
      table: {
      },
    },
  ],
};

const queryFields = ['id','userId','roleId'];
const editFields = ['userId','roleId'];
const tableFields = ['id','userId','roleId'];
const descriptionFields = ['id','userId','roleId'];

export const searchFormSchema: FormSchema[] = schema.properties.filter(item => queryFields.includes(item.field))
  .map(
    ({ field, label, form: { rules = [], ...formProps } }) =>
      ({
        field,
        label,
        defaultValue: undefined,
        rules: rules.filter((r) => !r.required),
        ...formProps,
      } as FormSchema),
  );

export const formSchema: FormSchema[] = schema.properties.filter(item => editFields.includes(item.field))
  .map(
    ({ field, label, defaultValue, form }) =>
      ({
        field,
        label,
        defaultValue,
        ...form,
        colProps: colPropsInDrawer,
      } as FormSchema),
  );

export const columns: BasicColumn[] = schema.properties.filter(item => tableFields.includes(item.field))
  .map(
    ({ field, label, table }) =>
      ({
        dataIndex: field,
        title: label,
        ...table,
      } as BasicColumn)
  );

export const descriptionColumns: BasicColumn[] = schema.properties.filter(item => descriptionFields.includes(item.field))
  .map(
    ({ field, label, table }) =>
      ({
        dataIndex: field,
        title: label,
        ...table,
      } as BasicColumn),
  );
