/* eslint-disable @typescript-eslint/unified-signatures */
import { HttpStep } from '../../HttpStep.js';
export const SubstringStepKind = 'HttpAction#Substring';
/**
 * Returns the part of the string from the start index up to and excluding the end index, or to the end
 * of the string if no end index is supplied.
 * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring
 */
export class SubstringStep extends HttpStep {
    kind = SubstringStepKind;
    /**
     * The index of the first character to include in the returned substring.
     */
    start;
    /**
     * The index of the first character to exclude from the returned substring.
     */
    end;
    constructor(startOrInit, end) {
        super();
        if (typeof startOrInit === 'object') {
            const typed = startOrInit;
            this.new(typed);
        }
        else if (typeof startOrInit === 'number') {
            this.new({
                kind: SubstringStepKind,
                start: startOrInit,
                end,
                enabled: true,
            });
        }
    }
    new(init) {
        super.new(init);
        this.kind = SubstringStepKind;
        if (typeof init.start === 'number') {
            this.start = init.start;
        }
        else {
            this.start = undefined;
        }
        if (typeof init.end === 'number') {
            this.end = init.end;
        }
        else {
            this.end = undefined;
        }
    }
    checkValidity() {
        return typeof this.start === 'number';
    }
    toJSON() {
        const result = {
            ...super.toJSON(),
            kind: SubstringStepKind,
        };
        if (typeof this.start === 'number') {
            result.start = this.start;
        }
        if (typeof this.end === 'number') {
            result.end = this.end;
        }
        return result;
    }
}
//# sourceMappingURL=SubstringStep.js.map