// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import { logger } from "../logger.js"; import { KnownVersions } from "../models/models.js"; import type { AzureSupportedClouds } from "../static-helpers/cloudSettingHelpers.js"; import { getArmEndpoint } from "../static-helpers/cloudSettingHelpers.js"; import type { Client, ClientOptions } from "@azure-rest/core-client"; import { getClient } from "@azure-rest/core-client"; import type { TokenCredential } from "@azure/core-auth"; export interface UsageManagementContext extends Client { /** The ID of the target subscription. The value must be an UUID. */ subscriptionId: string; /** The API version to use for this operation. */ /** Known values of {@link KnownVersions} that the service accepts. */ apiVersion?: string; } /** Optional parameters for the client. */ export interface UsageManagementClientOptionalParams extends ClientOptions { /** The API version to use for this operation. */ /** Known values of {@link KnownVersions} that the service accepts. */ apiVersion?: string; /** Specifies the Azure cloud environment for the client. */ cloudSetting?: AzureSupportedClouds; } export function createUsageManagement( credential: TokenCredential, subscriptionId: string, options: UsageManagementClientOptionalParams = {}, ): UsageManagementContext { const endpointUrl = options.endpoint ?? getArmEndpoint(options.cloudSetting) ?? "https://management.azure.com"; const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; const userAgentInfo = `azsdk-js-arm-commerce/4.0.0-beta.4`; const userAgentPrefix = prefixFromOptions ? `${prefixFromOptions} azsdk-js-api ${userAgentInfo}` : `azsdk-js-api ${userAgentInfo}`; const { apiVersion: _, ...updatedOptions } = { ...options, userAgentOptions: { userAgentPrefix }, loggingOptions: { logger: options.loggingOptions?.logger ?? logger.info }, credentials: { scopes: options.credentials?.scopes ?? [`${endpointUrl}/.default`] }, }; const clientContext = getClient(endpointUrl, credential, updatedOptions); const apiVersion = options.apiVersion; return { ...clientContext, apiVersion, subscriptionId } as UsageManagementContext; }