import { find } from "../../../util/host-rules.js";
import * as azure from "azure-devops-node-api";
import { getBasicHandler, getHandlerFromToken } 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);
	return getHandlerFromToken(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