/**
 * 项目：-
 * 模型分组：系统管理
 * 模型名称：角色权限对应表
 * @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: 'RoleAuthority',
  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: 'roleId',
      label: 'sys_role.id',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: 'sys_role.id',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入sys_role.id！' }],
      },
      table: {
      },
    },
    {
      field: 'authorityId',
      label: 'sys_authority.id',
      defaultValue: undefined,
      form: {
        componentProps: {
          allowClear: false,
          placeholder: 'sys_authority.id',
        },
        colProps,
        component: 'InputNumber',
        rules: [{ required: true, message: '请输入sys_authority.id！' }],
      },
      table: {
      },
    },
  ],
};

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

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),
  );
