import { c as normalizeOptionalString } from "./string-coerce-DW4mBlAt.js";
import { o as isRecord } from "./record-coerce-DHZ4bFlT.js";
import "./string-coerce-runtime-DsF17V0Z.js";
import { existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { homedir } from "node:os";
//#region extensions/google/oauth.settings.ts
const defaultFs = {
	existsSync,
	readFileSync,
	homedir
};
const OAUTH_SETTINGS_TEST_API_KEY = Symbol.for("openclaw.google.oauthSettingsTestApi");
let oauthSettingsFs = defaultFs;
function readSettingsFile() {
	const settingsPath = join(oauthSettingsFs.homedir(), ".gemini", "settings.json");
	if (!oauthSettingsFs.existsSync(settingsPath)) return null;
	try {
		const parsed = JSON.parse(oauthSettingsFs.readFileSync(settingsPath, "utf8"));
		return isRecord(parsed) ? parsed : null;
	} catch {
		return null;
	}
}
function setOAuthSettingsFsForTest(overrides) {
	oauthSettingsFs = overrides ? {
		...defaultFs,
		...overrides
	} : defaultFs;
}
function resolveGeminiCliSelectedAuthType() {
	const settings = readSettingsFile();
	if (settings) {
		const security = isRecord(settings.security) ? settings.security : void 0;
		const auth = isRecord(security?.auth) ? security.auth : void 0;
		const selectedAuthType = normalizeOptionalString(auth?.selectedType) ?? normalizeOptionalString(auth?.enforcedType) ?? normalizeOptionalString(settings.selectedAuthType) ?? normalizeOptionalString(settings.enforcedAuthType);
		if (selectedAuthType) return selectedAuthType;
	}
	if (process.env.GOOGLE_GENAI_USE_GCA === "true") return "oauth-personal";
}
function isGeminiCliPersonalOAuth() {
	return resolveGeminiCliSelectedAuthType() === "oauth-personal";
}
if (process.env.VITEST) globalThis[OAUTH_SETTINGS_TEST_API_KEY] = { setFs: setOAuthSettingsFsForTest };
//#endregion
export { isGeminiCliPersonalOAuth as t };
