import { loadAuthProfileStore } from "./store.js";
//#region src/auth/profiles/order.ts
/**
* Auth Profiles - Profile Order Resolution
* 
* Resolves the order of auth profiles for a provider (round-robin, etc).
*/
/**
* Resolve auth profile order for a provider.
* Uses stored order if available, otherwise returns default order.
*/
function resolveAuthProfileOrder(provider) {
	const store = loadAuthProfileStore();
	if (store.order && store.order[provider]) return store.order[provider];
	return [`${provider}:default`];
}
/**
* Get next profile in rotation for a provider.
* Considers last good profile and round-robin.
*/
function getNextProfileInRotation(provider, availableProfiles) {
	if (availableProfiles.length === 0) return;
	if (availableProfiles.length === 1) return availableProfiles[0];
	const lastGood = loadAuthProfileStore().lastGood?.[provider];
	if (lastGood) {
		const currentIndex = availableProfiles.indexOf(lastGood);
		if (currentIndex >= 0) return availableProfiles[(currentIndex + 1) % availableProfiles.length];
	}
	return availableProfiles[0];
}
/**
* Mark a profile as "good" (working)
*/
function markProfileGood(provider, profileId) {
	const store = loadAuthProfileStore();
	if (!store.lastGood) store.lastGood = {};
	store.lastGood[provider] = profileId;
	if (store.usageStats?.[profileId]) {
		delete store.usageStats[profileId].cooldownUntil;
		delete store.usageStats[profileId].disabledUntil;
		delete store.usageStats[profileId].disabledReason;
	}
	import("./store.js").then(({ saveAuthProfileStore }) => {
		saveAuthProfileStore(store);
	});
}
//#endregion
export { getNextProfileInRotation, markProfileGood, resolveAuthProfileOrder };

//# sourceMappingURL=order.js.map