import { DvnDataAdapter } from '@dvn/core/adapters/DvnDataAdapter';
import { DataTransferField } from '@dvn/core/doldurma/src/fields/query-include/data-transfer-field';
import { SingleChoiceField, SingleChoiceFieldOption } from '@dvn/core/doldurma/src/fields/single-choice';
import { FormViewConfig } from '@dvn/core/models/form-view-config';
import { AppViewType } from '@dvn/core/models/view-config';
import { dataConfigs } from '../../../../../mentornity-console/src/configs/data-configs';
import { FormHandlerMoveDomain } from '../../handlers/form-handler-move-domain';
import { damgaSpace } from '../data-configs';
export const ID = 'form-view-domain-move';
export const config = (apiDamga, products, workspaceOwnerships) => FormViewConfig.decode({
  _id: ID,
  base: 'devingen-dev',
  title: 'Move domain',
  space: damgaSpace,
  table: dataConfigs['damga-domains'],
  type: AppViewType.FormView,
  handler: new FormHandlerMoveDomain(apiDamga, ID),
  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('domainId'),
      },
      {
        field: new SingleChoiceField('targetProductId', 'Select product to move this domain', products
          .filter(p => p.type === 'damga')
          .map(product => (new SingleChoiceFieldOption(product.name, product._id, 'primary', workspaceOwnerships.find(w => w.workspace._id === product.workspace._id).workspace.name))), '', 'radioCard').setDataAdapter(new DvnDataAdapter('name', '_id'))
          .require(),
      },
    ],
    i18n: {
      submit: 'Move Domain'
    }
  },
  params: {
    domainId: {
      required: true,
    },
    domain: {
      required: true,
    },
    target: {
      required: true,
    },
    overrideHost: {
      required: true,
    },
    useTLS: {
      required: true,
    },
  },
});
