"use strict";
// ---------------------------------------------------------------------------
// PathDialect — query language abstraction for ASL emission
//
// The dialect encapsulates all query-language-specific patterns (path syntax,
// field names, value wrapping, structural choices) so that stateBuilder and
// expressionMapper remain dialect-agnostic.
// ---------------------------------------------------------------------------
Object.defineProperty(exports, "__esModule", { value: true });
exports.JSONATA_DIALECT = exports.JSON_PATH_DIALECT = exports.JsonataDialect = exports.JsonPathDialect = void 0;
// ---------------------------------------------------------------------------
// JSONPath dialect (used when queryLanguage: 'JSONPath' is explicitly set)
// ---------------------------------------------------------------------------
class JsonPathDialect {
    queryLanguage = undefined;
    resultPath(varName) {
        return `$.${varName}`;
    }
    resultPathDiscard() {
        return null;
    }
    variablePath(varName) {
        return `$.${varName}`;
    }
    inputRoot() {
        return '$';
    }
    contextRoot() {
        return '$$';
    }
    statesResult() {
        return '$';
    }
    statesErrorOutput() {
        return '$.error';
    }
    parallelTempResultPath() {
        return '$.__parallel';
    }
    parallelElementInputPath(index) {
        return `$.__parallel[${index}]`;
    }
    needsParallelPassChain() {
        return true;
    }
    emitParallelAssignment(_bindings) {
        return {};
    }
    mapItemValuePath() {
        return '$$.Map.Item.Value';
    }
    dynamicKey(name) {
        return `${name}.$`;
    }
    needsItemSelector() {
        return true;
    }
    wrapDynamicValue(path) {
        return path;
    }
    wrapIntrinsicResult(keyName, intrinsicPath) {
        return { [`${keyName}.$`]: intrinsicPath };
    }
    emitResultAssignment(varName) {
        return { ResultPath: `$.${varName}` };
    }
    emitResultDiscard() {
        return { ResultPath: null };
    }
    emitParameters(params) {
        return { Parameters: params };
    }
    emitItemsPath(path) {
        return { ItemsPath: path };
    }
    emitCatchAssignment(paramName) {
        return { ResultPath: `$.${paramName}` };
    }
    emitReturnPath(path) {
        return { InputPath: path };
    }
    emitPassOutput(params) {
        return { Parameters: params };
    }
    emitDynamicWaitField(field, path) {
        return { [`${field}Path`]: path };
    }
    emitDynamicTimeout(field, path) {
        return { [`${field}Path`]: path };
    }
    emitDynamicFailCause(path) {
        return { CausePath: path };
    }
    isJsonata() {
        return false;
    }
    extractVarName(path) {
        const match = path.match(/^\$\.(\w+)/);
        return match ? match[1] : null;
    }
}
exports.JsonPathDialect = JsonPathDialect;
// ---------------------------------------------------------------------------
// JSONata dialect
// ---------------------------------------------------------------------------
class JsonataDialect {
    queryLanguage = 'JSONata';
    resultPath(varName) {
        return `$${varName}`;
    }
    resultPathDiscard() {
        return null;
    }
    variablePath(varName) {
        return `$${varName}`;
    }
    inputRoot() {
        return '$states.input';
    }
    contextRoot() {
        return '$states.context';
    }
    statesResult() {
        return '$states.result';
    }
    statesErrorOutput() {
        return '$states.errorOutput';
    }
    parallelTempResultPath() {
        // Not used in JSONata mode (needsParallelPassChain returns false)
        return '$states.result';
    }
    parallelElementInputPath(index) {
        // Not used in JSONata mode (needsParallelPassChain returns false)
        return `$states.result[${index}]`;
    }
    needsParallelPassChain() {
        return false;
    }
    emitParallelAssignment(bindings) {
        const assign = {};
        for (const { name, index } of bindings) {
            assign[name] = `{% $states.result[${index}] %}`;
        }
        return { Assign: assign };
    }
    mapItemValuePath() {
        return '$states.input';
    }
    dynamicKey(name) {
        return name;
    }
    needsItemSelector() {
        return false;
    }
    wrapDynamicValue(path) {
        return `{% ${path} %}`;
    }
    wrapIntrinsicResult(keyName, intrinsicPath) {
        return { [keyName]: `{% ${intrinsicPath} %}` };
    }
    emitResultAssignment(varName) {
        return { Assign: { [varName]: '{% $states.result %}' } };
    }
    emitResultDiscard() {
        return {};
    }
    emitParameters(params) {
        return { Arguments: params };
    }
    emitItemsPath(path) {
        return { Items: `{% ${path} %}` };
    }
    emitCatchAssignment(paramName) {
        return { Assign: { [paramName]: '{% $states.errorOutput %}' } };
    }
    emitReturnPath(path) {
        return { Output: `{% ${path} %}` };
    }
    emitPassOutput(params) {
        return { Output: params };
    }
    emitDynamicWaitField(field, path) {
        return { [field]: `{% ${path} %}` };
    }
    emitDynamicTimeout(field, path) {
        return { [field]: `{% ${path} %}` };
    }
    emitDynamicFailCause(path) {
        return { Cause: `{% ${path} %}` };
    }
    isJsonata() {
        return true;
    }
    extractVarName(path) {
        // Match $varName (JSONata) — no dot after $
        const match = path.match(/^\$(\w+)/);
        return match ? match[1] : null;
    }
}
exports.JsonataDialect = JsonataDialect;
/** Singleton instance for the JSONPath dialect. */
exports.JSON_PATH_DIALECT = new JsonPathDialect();
/** Singleton instance for the JSONata dialect. */
exports.JSONATA_DIALECT = new JsonataDialect();
//# sourceMappingURL=pathDialect.js.map