import { DataTransferField } from '@dvn/core/doldurma/src/fields/query-include/data-transfer-field';
import { TextField } from '@dvn/core/doldurma/src/fields/text';
import { ModifierTrimmer } from '@dvn/core/doldurma/src/interceptors/modifiers/ModifierTrimmer';
import { ValidatorLength } from '@dvn/core/doldurma/src/interceptors/validators/ValidatorLength';
import { ValidatorRegex } from '@dvn/core/doldurma/src/interceptors/validators/ValidatorRegex';
import { FormViewConfig } from '@dvn/core/models/form-view-config';
import { AppViewType } from '@dvn/core/models/view-config';
import { spaces } from '../spaces';
import { ChangeOrganisationDomainFormHandler } from '../../handlers/ChangeOrganisationDomainFormHandler';
import { dataConfigs } from '../data-configs';
export const ID = 'form-view-organisation-change-domain';
export const viewConfig = FormViewConfig.decode({
  _id: ID,
  base: 'mentornity',
  title: 'Change Organisation Domain',
  space: spaces['mentornity'],
  table: dataConfigs['organisations'],
  type: AppViewType.FormView,
  handler: new ChangeOrganisationDomainFormHandler(),
  ui: {
    fields: [
      // this field is passed by the parameters. this is a data holder field to pass the data to form handler
      {
        field: new DataTransferField('organisationId'),
      },
      {
        field: new TextField('domain', 'New domain').addInterceptor('onSubmit', new ValidatorRegex('[a-z0-9\-]'))
          .addInterceptor('onSubmit', new ValidatorLength(2, 100))
          .addInterceptor('onSubmit', new ModifierTrimmer())
          .require(),
      },
    ],
  },
});
