"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.qVersionCatalogs = void 0;
const good_enough_parser_1 = require("good-enough-parser");
const common_1 = require("./common");
const handlers_1 = require("./handlers");
const qGroupId = (0, common_1.qConcatExpr)(common_1.qTemplateString, common_1.qPropertyAccessIdentifier, common_1.qVariableAccessIdentifier).handler((ctx) => (0, common_1.storeInTokenMap)(ctx, 'groupId'));
const qArtifactId = (0, common_1.qConcatExpr)(common_1.qTemplateString, common_1.qPropertyAccessIdentifier, common_1.qVariableAccessIdentifier).handler((ctx) => (0, common_1.storeInTokenMap)(ctx, 'artifactId'));
const qVersionCatalogVersion = good_enough_parser_1.query
    .op('.')
    .alt(
// library("kotlin-reflect", "org.jetbrains.kotlin", "kotlin-reflect").versionRef("kotlin")
good_enough_parser_1.query.sym('versionRef').tree({
    maxDepth: 1,
    startsWith: '(',
    endsWith: ')',
    search: good_enough_parser_1.query.begin().join(common_1.qStringValueAsSymbol).end(),
}), 
// library("android-gradle", "com.android.tools.build", "gradle").version("${agp}")
good_enough_parser_1.query.sym('version').tree({
    maxDepth: 1,
    startsWith: '(',
    endsWith: ')',
    search: good_enough_parser_1.query
        .begin()
        .join((0, common_1.qConcatExpr)(common_1.qTemplateString, common_1.qPropertyAccessIdentifier, common_1.qVariableAccessIdentifier))
        .end(),
}))
    .handler((ctx) => (0, common_1.storeInTokenMap)(ctx, 'version'));
// library("foo.bar", "foo", "bar")
const qVersionCatalogDependencies = good_enough_parser_1.query
    .sym('library', common_1.storeVarToken)
    .handler((ctx) => (0, common_1.storeInTokenMap)(ctx, 'methodName'))
    .tree({
    type: 'wrapped-tree',
    maxDepth: 1,
    startsWith: '(',
    endsWith: ')',
    search: good_enough_parser_1.query
        .begin()
        .join(common_1.qStringValue)
        .handler((ctx) => (0, common_1.storeInTokenMap)(ctx, 'alias'))
        .op(',')
        .join(qGroupId)
        .op(',')
        .join(qArtifactId)
        .end(),
})
    .opt(qVersionCatalogVersion)
    .handler(handlers_1.handleLibraryDep)
    .handler(common_1.cleanupTempVars);
// alias("foo.bar").to("foo", "bar").version("1.2.3")
const qVersionCatalogAliasDependencies = good_enough_parser_1.query
    .sym('alias')
    .tree({
    type: 'wrapped-tree',
    maxDepth: 1,
    startsWith: '(',
    endsWith: ')',
    search: good_enough_parser_1.query
        .begin()
        .join(common_1.qStringValue)
        .handler((ctx) => (0, common_1.storeInTokenMap)(ctx, 'alias'))
        .end(),
})
    .op('.')
    .sym('to')
    .tree({
    type: 'wrapped-tree',
    maxDepth: 1,
    startsWith: '(',
    endsWith: ')',
    search: good_enough_parser_1.query.begin().join(qGroupId).op(',').join(qArtifactId).end(),
})
    .opt(qVersionCatalogVersion)
    .handler(handlers_1.handleLibraryDep)
    .handler(common_1.cleanupTempVars);
exports.qVersionCatalogs = good_enough_parser_1.query.alt(qVersionCatalogDependencies, qVersionCatalogAliasDependencies);
//# sourceMappingURL=version-catalogs.js.map