/* eslint-disable @typescript-eslint/unified-signatures */
import { FlowSourceEnum } from '../../HttpFlows.js';
import { HttpStep } from '../../HttpStep.js';
export const ReadDataStepKind = 'HttpAction#ReadData';
export class ReadDataStep extends HttpStep {
    kind = ReadDataStepKind;
    /**
     * The main data source.
     * In the legacy actions this was `type`.
     */
    source;
    /**
     * Source of the data.
     * In the legacy actions this was `source`.
     * This is not required when the source is not `request` or `response`.
     */
    data;
    /**
     * The path to the data.
     * For JSON value use https://jmespath.org/ syntax.
     * For XML use xpath.
     * For any other use a simple path to the data separated by dot (e.g. headers.content-type)
     */
    path;
    constructor(sourceOrInit, path, data) {
        super();
        if (!sourceOrInit) {
            return;
        }
        if (typeof sourceOrInit === 'object') {
            const typed = sourceOrInit;
            this.new(typed);
        }
        else if (typeof sourceOrInit === 'string') {
            this.new({
                kind: ReadDataStepKind,
                source: sourceOrInit,
                data,
                path,
                enabled: true,
            });
        }
    }
    new(init) {
        super.new(init);
        this.kind = ReadDataStepKind;
        this.source = init.source;
        this.data = init.data;
        this.path = init.path;
    }
    checkValidity() {
        const { source, path, data } = this;
        if (!source && !path) {
            return false;
        }
        if (source === FlowSourceEnum.variable) {
            return true;
        }
        return !!data;
    }
    toJSON() {
        const result = {
            ...super.toJSON(),
            kind: ReadDataStepKind,
        };
        if (this.source) {
            result.source = this.source;
        }
        if (this.data) {
            result.data = this.data;
        }
        if (this.path) {
            result.path = this.path;
        }
        return result;
    }
}
//# sourceMappingURL=ReadDataStep.js.map