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

export const IsEmptyAssertionKind = 'HttpAction#IsEmptyAssertion'

/**
 * An assertion that makes sure the input is empty (empty array, empty string, empty object - no properties)
 */
export interface IIsEmptyAssertion extends IHttpStep {
  kind: typeof IsEmptyAssertionKind
}

/**
 * An assertion that makes sure the input is empty (empty array, empty string, empty object - no properties)
 */
export class IsEmptyAssertion extends HttpStep {
  override kind = IsEmptyAssertionKind

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

  override new(init: IIsEmptyAssertion): void {
    super.new(init)
    this.kind = IsEmptyAssertionKind
  }

  checkValidity(): boolean {
    return true
  }

  override toJSON(): IIsEmptyAssertion {
    const result: IIsEmptyAssertion = {
      ...super.toJSON(),
      kind: IsEmptyAssertionKind,
    }
    return result
  }
}
