import { DateField } from '@dvn/core/doldurma/src/fields/date';
import { DateDataType } from '@dvn/core/doldurma/src/fields/date/date';
import { NestedField } from '@dvn/core/doldurma/src/fields/nested/nested';
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 { TextField } from '@dvn/core/doldurma/src/fields/text';
import { ViewPlacement } from '@dvn/core/models/app-config';
import { Comparison } from '@dvn/core/models/filter';
import { TableListViewConfig } from '@dvn/core/models/table-list-view-config';
import { AppViewType } from '@dvn/core/models/view-config';
import { dataConfigs } from '../data-configs';
import { spaces } from '../spaces';
import * as detailViewScheduledJobSendEmail from './detail-view-scheduled-job-send-email';
export const ID = 'table-list-view-scheduled-job-send-email';
export const tableListViewUIConfigScheduledJobs = TableListViewConfig.decode({
  main: {
    actions: [{
        ui: {
          name: 'expand',
          buttonType: 'icon-button',
          iconName: 'uil uil-expand-alt',
          view: 'flat'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: ViewPlacement.SideModal,
          viewId: detailViewScheduledJobSendEmail.ID,
          params: {
            conversionConfig: {
              'item._id': 'itemId',
            }
          }
        }
      }],
    fields: [
      {
        fieldId: 'parameters.templateAndSubjectName',
        fieldDisplay: new NestedField('parameters.templateAndSubjectName', new TextField('templateAndSubjectName', 'Type')),
      },
      {
        fieldId: 'createdAt',
        fieldDisplay: new DateField('createdAt', 'Date').setDateFormat('DD MMM YYYY').setDataType(DateDataType.Unix),
      },
      {
        fieldId: 'createdAt',
        fieldDisplay: new DateField('createdAt', 'Hour').setDateFormat('HH:mm').setDataType(DateDataType.Unix),
      },
      {
        fieldId: 'parameters.senderName',
        fieldDisplay: new NestedField('parameters.senderName', new TextField('senderName', 'Sender')),
      },
      {
        fieldId: 'parameters.recipientEmail',
        fieldDisplay: new NestedField('parameters.recipientEmail', new TextField('recipientEmail', 'Recipient')),
      },
      {
        fieldId: 'metadata.sent',
        fieldDisplay: new NestedField('metadata.sent', new DateField('sentOn', 'Sent On').setDateFormat('DD MMM HH:mm')),
      },
      {
        fieldId: 'metadata.delivered',
        fieldDisplay: new NestedField('metadata.delivered', new DateField('deliveredOn', 'Delivered On').setDateFormat('DD MMM HH:mm')),
      },
      {
        fieldId: 'status',
      },
    ],
    columns: {
      createdAt: {
        width: 100,
      },
      status: {
        width: 100,
      },
    },
  },
  quickSearch: {
    fields: [
      { field: new TextField('parameters.recipientEmail', 'Recipient') },
      {
        field: new SingleChoiceField('parameters.templateAndSubjectName', 'Type', [
          new SingleChoiceFieldOption('Announcement', 'Announcement'),
          new SingleChoiceFieldOption('Accept Pair Request', 'AcceptSubscription'),
          new SingleChoiceFieldOption('Reject Pair Request', 'RejectSubscription'),
          new SingleChoiceFieldOption('New Pair', 'CreateSubscription'),
          new SingleChoiceFieldOption('New Availability', 'CreateAvailability'),
          new SingleChoiceFieldOption('Cancel Meeting', 'CancelEvent'),
          new SingleChoiceFieldOption('New Meeting', 'CreateEvent'),
          new SingleChoiceFieldOption('New Meeting for Goal', 'CreateEventForMeetingGoal'),
          new SingleChoiceFieldOption('Update Meeting', 'UpdateEvent'),
          new SingleChoiceFieldOption('Invitation', 'Invitation'),
          new SingleChoiceFieldOption('New Form Assignment', 'FormAssignment'),
          new SingleChoiceFieldOption('New Group Member', 'NewGroupMember'),
          new SingleChoiceFieldOption('New Message', 'NewMessage'),
          new SingleChoiceFieldOption('Reset Password Link', 'ResetPasswordLink'),
        ]),
      }
    ],
    ui: {
      'parameters.templateAndSubjectName': {
        width: '240px',
      }
    },
    requireFilters: true,
  },
});
export const viewConfig = TableListViewConfig.decode({
  _id: ID,
  type: AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Send Email Jobs',
  space: spaces['mentornity'],
  table: dataConfigs['scheduledjobs'],
  query: {
    fields: [
      new TextField('name', 'Name'),
      new TextField('status', 'Status'),
      new DateField('scheduledAt', 'Created At'),
      new DateField('createdAt', 'Created At'),
      new DataTransferField('parameters'),
      new DataTransferField('metadata'),
    ],
    filter: {
      filters: [
        {
          comparison: Comparison.Eq,
          id: 'name',
          value: 'SendEmail',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: tableListViewUIConfigScheduledJobs,
});
