import { logger } from "../../../logger/index.js";
import { find } from "../../../util/host-rules.js";
import { isProbablyJwt } from "../../../util/http/jwt.js";
import * as azure from "azure-devops-node-api";
import { getBasicHandler, getBearerHandler, getPersonalAccessTokenHandler } from "azure-devops-node-api";
//#region lib/modules/platform/azure/azure-got-wrapper.ts
const hostType = "azure";
let endpoint;
function getAuthenticationHandler(config) {
	if (!config.token && config.username && config.password) return getBasicHandler(config.username, config.password, true);
	if (config.token && isProbablyJwt(config.token)) {
		logger.debug("Using Bearer authentication (JWT detected)");
		return getBearerHandler(config.token, true);
	}
	logger.debug("Using PAT authentication");
	return getPersonalAccessTokenHandler(config.token, true);
}
function azureObj() {
	const config = find({
		hostType,
		url: endpoint
	});
	if (!config.token && !(config.username && config.password)) throw new Error(`No config found for azure`);
	const authHandler = getAuthenticationHandler(config);
	return new azure.WebApi(endpoint, authHandler, {
		allowRetries: true,
		maxRetries: 2
	});
}
function gitApi() {
	return azureObj().getGitApi();
}
function coreApi() {
	return azureObj().getCoreApi();
}
function policyApi() {
	return azureObj().getPolicyApi();
}
function workItemTrackingApi() {
	return azureObj().getWorkItemTrackingApi();
}
function setEndpoint(e) {
	endpoint = e;
}
//#endregion
export { azureObj, coreApi, gitApi, policyApi, setEndpoint, workItemTrackingApi };

//# sourceMappingURL=azure-got-wrapper.js.map