import { InvalidationAction } from '@dvn/core/models/actions';
export class FormHandlerMoveDomain {
  constructor(apiDamga, sourceViewId) {
    this.sourceViewId = sourceViewId;
    this.api = apiDamga;
  }
  onSubmit(event) {
    const { values: { domainId, targetProductId } } = event.detail;
    return new Promise((resolve, reject) => {
      this.api.moveDomain(domainId, {
        productId: targetProductId,
      }).then(() => {
        resolve({
          events: [
            new InvalidationAction(this.sourceViewId, 'table-list-view-domain'),
          ],
          navigation: {
            type: 'navigation',
            direction: 'back'
          }
        });
      }).catch(() => {
        reject(['Unexpected error']);
      });
    });
  }
}
