import { ConfigService } from "../../configService/index.mjs";
import { apiMutate } from "../../utilities/useAxiosMutate.mjs";
//#region src/integrations/outlook/outlookIntegrationClient.ts
const CONTROLLER = "OutlookIntegrationToken";
const OUTLOOK_CALLBACK_PATH = "/auth/outlook/callback";
async function getStatus() {
	const { data } = await apiMutate(ensureBaseUrl(), `${CONTROLLER}/status`, {
		method: "get",
		headers: productHeaders()
	}, void 0);
	return data ?? { connected: false };
}
async function getAuthorizeUrl(request) {
	const { data } = await apiMutate(ensureBaseUrl(), `${CONTROLLER}/authorize-url`, {
		method: "post",
		headers: productHeaders(),
		data: request
	}, void 0);
	return data;
}
async function exchangeAuthorizationCode(request) {
	const { data } = await apiMutate(ensureBaseUrl(), `${CONTROLLER}/oauth/exchange`, {
		method: "post",
		headers: productHeaders(),
		data: request
	}, void 0);
	return data;
}
async function disconnect() {
	await apiMutate(ensureBaseUrl(), `${CONTROLLER}/disconnect`, {
		method: "post",
		headers: productHeaders()
	}, void 0);
}
async function sendMail(payload) {
	await apiMutate(ensureBaseUrl(), `${CONTROLLER}/send-mail`, {
		method: "post",
		headers: productHeaders(),
		data: payload
	}, void 0);
}
async function checkAndAuthenticate() {
	await apiMutate(ensureBaseUrl(), `${CONTROLLER}/authenticate`, {
		method: "post",
		headers: productHeaders()
	}, void 0);
}
function getOutlookRedirectUri() {
	if (typeof window !== "undefined" && window.location) return `${window.location.origin}${OUTLOOK_CALLBACK_PATH}`;
	return `${String(ConfigService?.config?.UNITY_URL ?? "").replace(/\/$/, "")}${OUTLOOK_CALLBACK_PATH}`;
}
function ensureBaseUrl() {
	return ConfigService.integrationV2ApiUrl;
}
function productHeaders() {
	const rawId = ConfigService?.config?.UNITY_PRODUCT_ID;
	const normalized = String(rawId ?? "").trim();
	if (!normalized) throw new Error("UNITY_PRODUCT_ID is not configured.");
	const numericId = Number(normalized);
	if (!Number.isFinite(numericId) || numericId <= 0) throw new Error("UNITY_PRODUCT_ID must be a positive number.");
	return { productId: String(numericId) };
}
//#endregion
export { checkAndAuthenticate, disconnect, exchangeAuthorizationCode, getAuthorizeUrl, getOutlookRedirectUri, getStatus, sendMail };

//# sourceMappingURL=outlookIntegrationClient.mjs.map