"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.allVirtualParameters = exports.allVirtualProperties = exports.resolveParameterNames = exports.resolvePropertyNames = void 0;
const codegen_1 = require("@azure-tools/codegen");
const linq_1 = require("@azure-tools/linq");
function resolvePropertyNames(reservedNames, virtualProperties) {
    const usedNames = new Set(reservedNames);
    const allProps = (0, linq_1.values)(virtualProperties.owned, virtualProperties.inherited, virtualProperties.inlined).toArray();
    for (const prop of allProps) {
        if (usedNames.has(prop.name)) {
            prop.name = (0, codegen_1.selectName)(prop.nameOptions, usedNames);
        }
        else {
            usedNames.add(prop.name);
        }
    }
}
exports.resolvePropertyNames = resolvePropertyNames;
function resolveParameterNames(reservedNames, virtualParameters) {
    const usedNames = new Set(reservedNames);
    const collisions = new Set();
    // we need to make sure we avoid name collisions. operation parameters get first crack.
    for (const each of (0, linq_1.values)(virtualParameters.operation)) {
        if (usedNames.has(each.name)) {
            collisions.add(each);
        }
        else {
            usedNames.add(each.name);
        }
    }
    // handle operation parameters
    for (const each of collisions) {
        each.name = (0, codegen_1.selectName)(each.nameOptions, usedNames);
    }
    collisions.clear();
    // now do body parameters.
    for (const each of (0, linq_1.values)(virtualParameters.body)) {
        if (usedNames.has(each.name)) {
            collisions.add(each);
        }
        else {
            usedNames.add(each.name);
        }
    }
    for (const each of collisions) {
        each.name = (0, codegen_1.selectName)(each.nameOptions, usedNames);
    }
}
exports.resolveParameterNames = resolveParameterNames;
function allVirtualProperties(virtualProperties) {
    return virtualProperties ? (0, linq_1.values)(virtualProperties.owned, virtualProperties.inherited, virtualProperties.inlined).toArray() : [];
}
exports.allVirtualProperties = allVirtualProperties;
function allVirtualParameters(virtualParameters) {
    return virtualParameters ? (0, linq_1.values)(virtualParameters.operation, virtualParameters.body).toArray() : [];
}
exports.allVirtualParameters = allVirtualParameters;
//# sourceMappingURL=resolve-conflicts.js.map