"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParameterCollection = void 0;
/**
 * @internal
 */
class ParameterCollection {
    constructor(prior) {
        // let bodyCode = () =>
        {
            if (prior && prior.sequence) {
                this.sequence = prior.sequence.slice();
            }
            else {
                this.sequence = [];
            }
            if (prior && prior.lookup) {
                this.lookup = new Map(prior.lookup);
            }
            else {
                this.lookup = new Map();
            }
            if (prior && prior.ordinals) {
                this.ordinals = new Map(prior.ordinals);
            }
            else {
                this.ordinals = new Map();
            }
        }
        // return p.measure(bodyCode);
    }
    add(element) {
        // let bodyCode = () =>
        {
            // if there is already a named parameter that matches, this is trouble
            const name = element.getName();
            if (name) {
                if (this.lookup.has(name)) {
                    // why not just replace the old one?
                    this.lookup.set(name, element);
                    this.sequence[this.sequence.indexOf(this.sequence.find((e) => e.getName() === name))] = element;
                    this.ordinals.set(element, this.sequence.length);
                    return;
                }
                this.lookup.set(name, element);
            }
            this.ordinals.set(element, this.sequence.length);
            this.sequence.push(element);
        }
        // return p.measure(bodyCode);
    }
    resolveParameter(ordinal, name) {
        // let bodyCode = () =>
        {
            if (name) {
                if (this.lookup.has(name)) {
                    return this.lookup.get(name);
                }
                throw new Error(`there is no parameter named '${name}'`);
            }
            if (ordinal >= this.sequence.length) {
                throw new Error(`too many arguments supplied`);
            }
            return this.sequence[ordinal];
        }
        // return p.measure(bodyCode);
    }
    fetchParameterIndex(pName) {
        // let bodyCode = () =>
        {
            return this.ordinals.get(this.lookup.get(pName));
        }
        // return p.measure(bodyCode);
    }
}
exports.ParameterCollection = ParameterCollection;
//# sourceMappingURL=ParameterCollection.js.map