"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildFilteredServiceBindings = buildFilteredServiceBindings;
const buildInstanceBinding_1 = require("../../binding/calculations/buildInstanceBinding");
function buildFilteredServiceBindings(params, bindingConstraints, options) {
    const serviceIdentifier = options?.customServiceIdentifier ?? bindingConstraints.serviceIdentifier;
    const serviceBindings = options?.chained === true
        ? [...params.operations.getBindingsChained(serviceIdentifier)]
        : [...(params.operations.getBindings(serviceIdentifier) ?? [])];
    const filteredBindings = serviceBindings.filter((binding) => binding.isSatisfiedBy(bindingConstraints));
    if (filteredBindings.length === 0 &&
        params.autobindOptions !== undefined &&
        typeof serviceIdentifier === 'function') {
        const binding = (0, buildInstanceBinding_1.buildInstanceBinding)(params.autobindOptions, serviceIdentifier);
        params.operations.setBinding(binding);
        if (binding.isSatisfiedBy(bindingConstraints)) {
            filteredBindings.push(binding);
        }
    }
    return filteredBindings;
}
//# sourceMappingURL=buildFilteredServiceBindings.js.map