import { getOperationLink } from "@azure-tools/typespec-azure-core";
import { listOperationGroups, listOperationsInOperationGroup, } from "@azure-tools/typespec-client-generator-core";
export class ClientContext {
    constructor(baseUri, hostParameters, globalParameters, apiVersions) {
        this.baseUri = baseUri;
        this.hostParameters = hostParameters;
        this.globalParameters = globalParameters;
        this.apiVersions = apiVersions === null || apiVersions === void 0 ? void 0 : apiVersions.map((it) => it.version);
        this.ignoredOperations = new Set();
    }
    addGlobalParameter(parameter) {
        if (!this.globalParameters.includes(parameter)) {
            this.globalParameters.push(parameter);
        }
    }
    getAddedVersions(versions) {
        // currently only allow one added version
        const addedVersions = [];
        const addedVersion = versions.shift().value;
        if (this.apiVersions) {
            let includeVersion = false;
            for (const version of this.apiVersions) {
                if (version === addedVersion) {
                    includeVersion = true;
                }
                if (includeVersion) {
                    addedVersions.push(version);
                }
            }
        }
        return addedVersions;
    }
    preProcessOperations(sdkContext, client) {
        const operationGroups = listOperationGroups(sdkContext, client);
        const operations = listOperationsInOperationGroup(sdkContext, client);
        for (const operation of operations) {
            const opLink = getOperationLink(sdkContext.program, operation, "polling");
            if (opLink && opLink.linkedOperation) {
                this.ignoredOperations.add(opLink.linkedOperation);
            }
        }
        for (const operationGroup of operationGroups) {
            const operations = listOperationsInOperationGroup(sdkContext, operationGroup);
            for (const operation of operations) {
                const opLink = getOperationLink(sdkContext.program, operation, "polling");
                if (opLink && opLink.linkedOperation) {
                    this.ignoredOperations.add(opLink.linkedOperation);
                }
            }
        }
    }
}
//# sourceMappingURL=models.js.map