import { resolvePermissionProfile } from "../operating-model.js";
import { loadEffectiveSFPreferences } from "../preferences.js";

export function resolveUokFlags(prefs) {
	const uok = prefs?.uok;
	const enabledByPreference = uok?.enabled ?? true;
	return {
		enabled: enabledByPreference,
		gates: uok?.gates?.enabled ?? true,
		securityGuard: uok?.security_guard?.enabled ?? true,
		multiPackageHealing: uok?.multi_package_healing?.enabled ?? true,
		chaosMonkey: uok?.chaos_monkey?.enabled ?? false,
		autonomousCostGuard: uok?.cost_guard?.enabled ?? true,
		outcomeLearning: uok?.outcome_learning?.enabled ?? true,
		modelPolicy: uok?.model_policy?.enabled ?? true,
		executionGraph: uok?.execution_graph?.enabled ?? true,
		gitops: uok?.gitops?.enabled ?? true,
		gitopsTurnAction: uok?.gitops?.turn_action ?? "commit",
		gitopsTurnPush: uok?.gitops?.turn_push === true,
		auditEnvelope:
			(uok?.audit_envelope?.enabled ?? true) ||
			(uok?.audit_unified?.enabled ?? true),
		planningFlow:
			(uok?.planning_flow?.enabled ?? true) || (uok?.plan_v2?.enabled ?? true),
		permissionProfile: resolvePermissionProfile(uok?.permission_profile),
		phaseReview: uok?.phase_review?.enabled ?? false,
	};
}
export function loadUokFlags() {
	const prefs = loadEffectiveSFPreferences()?.preferences;
	return resolveUokFlags(prefs);
}
