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