import * as EffectConfig from "effect/Config";
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Redacted from "effect/Redacted";
import { ConfigError } from "@distilled.cloud/core/errors";
/**
 * Default base URL for Azure Resource Manager (ARM) API.
 */
export const DEFAULT_API_BASE_URL = "https://management.azure.com";
export class Credentials extends Context.Service()("AzureCredentials") {
}
const envConfig = EffectConfig.all({
    bearerToken: EffectConfig.string("AZURE_BEARER_TOKEN"),
    subscriptionId: EffectConfig.string("AZURE_SUBSCRIPTION_ID"),
    tenantId: EffectConfig.option(EffectConfig.string("AZURE_TENANT_ID")),
    apiBaseUrl: EffectConfig.string("AZURE_API_BASE_URL").pipe(EffectConfig.withDefault(DEFAULT_API_BASE_URL)),
});
/**
 * Reads Azure credentials from environment variables:
 *
 * - `AZURE_BEARER_TOKEN` — OAuth2 bearer token (required)
 * - `AZURE_SUBSCRIPTION_ID` — Azure subscription ID (required)
 * - `AZURE_TENANT_ID` — Azure tenant/directory ID (optional)
 * - `AZURE_API_BASE_URL` — Optional override for the API base URL
 */
export const CredentialsFromEnv = Layer.effect(Credentials, envConfig.asEffect().pipe(Effect.mapError(() => new ConfigError({
    message: "AZURE_BEARER_TOKEN and AZURE_SUBSCRIPTION_ID environment variables are required",
})), Effect.map(({ bearerToken, subscriptionId, tenantId, apiBaseUrl }) => ({
    bearerToken: Redacted.make(bearerToken),
    subscriptionId,
    tenantId: Option.getOrUndefined(tenantId),
    apiBaseUrl,
}))));
//# sourceMappingURL=credentials.js.map