export class BaseField {
  constructor(id, type) {
    this.id = id;
    this.type = type;
  }
  static decode(json) {
    return Object.assign(Object.create(BaseField.prototype), json);
  }
  getDisplayValue(value) {
    // should be overwritten by child classes
    return value;
  }
  /**
   * Appends new interceptor to the given interceptor type list.
   * @param type
   * @param interceptor
   */
  addInterceptor(type, interceptor) {
    if (!this.interceptors) {
      this.interceptors = {};
    }
    this.interceptors = Object.assign(Object.assign({}, this.interceptors), { [type]: [...(this.interceptors[type] || []), interceptor] });
    return this;
  }
  setRequired(required) {
    this.required = required;
    return this;
  }
  require() {
    this.required = true;
    return this;
  }
  setDisabled(disabled) {
    this.disabled = disabled;
    return this;
  }
  disable() {
    this.disabled = true;
    return this;
  }
  hide() {
    this.visible = false;
    return this;
  }
  setVisibility(visible) {
    this.visible = visible;
    return this;
  }
  setValue(value) {
    this.value = value;
    return this;
  }
  setErrorTitle(title) {
    this.errorTitle = title;
    return this;
  }
}
