/**
 * The action that can be taken on the data.
 */
export interface IHttpStep {
  /**
   * The kind of the action to perform.
   */
  kind: string
  /**
   * Whether the step is disabled in the flow.
   */
  enabled?: boolean
}

export abstract class HttpStep {
  /**
   * The kind of the action to perform.
   */
  kind = ''

  /**
   * Whether the step is disabled in the flow.
   */
  enabled?: boolean

  new(init: IHttpStep): void {
    const { kind, enabled } = init
    this.kind = kind
    if (typeof enabled === 'boolean') {
      this.enabled = enabled
    } else {
      this.enabled = undefined
    }
  }

  toJSON(): IHttpStep {
    const result: IHttpStep = {
      kind: this.kind,
    }
    if (typeof this.enabled === 'boolean') {
      result.enabled = this.enabled
    }
    return result
  }

  /**
   * A function that returns true when the step is valid and can be executed.
   */
  abstract checkValidity(): boolean
}
