import { HttpStep, IHttpStep } from '../../HttpStep.js'

export const TrimStepKind = 'HttpAction#Trim'

/**
 * Reads the input and trims it.
 * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim.
 */
export interface ITrimStep extends IHttpStep {
  kind: typeof TrimStepKind
}

/**
 * Reads the input and trims it.
 * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim.
 */
export class TrimStep extends HttpStep {
  override kind = TrimStepKind

  constructor(init?: ITrimStep) {
    super()
    if (typeof init === 'object') {
      this.new(init)
    }
  }

  override new(init: ITrimStep): void {
    super.new(init)
    this.kind = TrimStepKind
  }

  checkValidity(): boolean {
    return true
  }

  override toJSON(): ITrimStep {
    const result: ITrimStep = {
      ...super.toJSON(),
      kind: TrimStepKind,
    }
    return result
  }
}
