import type { AssertEqual, Equals, Keys, Values, ExperimentId, Experiments } from "@roo-code/types"

export const parallelToolCallsEnabled = false

export const EXPERIMENT_IDS = {
	CHAT_SEARCH: "chatSearch",
	USE_KPT_TREE: "useKPTtree",
	COMMIT_REVIEW: "commitReview",
	USE_LITE_PROMPTS: "useLitePrompts",
	PREVENT_FOCUS_DISRUPTION: "preventFocusDisruption",
	IMAGE_GENERATION: "imageGeneration",
	RUN_SLASH_COMMAND: "runSlashCommand",
	CUSTOM_TOOLS: "customTools",
	SMART_MISTAKE_DETECTION: "smartMistakeDetection",
} as const satisfies Record<string, ExperimentId>

// type _AssertExperimentIds = AssertEqual<Equals<ExperimentId, Values<typeof EXPERIMENT_IDS>>>

type ExperimentKey = Keys<typeof EXPERIMENT_IDS>

interface ExperimentConfig {
	enabled?: boolean
}

export const experimentConfigsMap: Record<ExperimentKey, ExperimentConfig> = {
	CHAT_SEARCH: { enabled: false },
	SMART_MISTAKE_DETECTION: { enabled: false },
	USE_KPT_TREE: { enabled: undefined },
	COMMIT_REVIEW: { enabled: false },
	USE_LITE_PROMPTS: { enabled: false },
	PREVENT_FOCUS_DISRUPTION: { enabled: false },
	IMAGE_GENERATION: { enabled: false },
	RUN_SLASH_COMMAND: { enabled: false },
	CUSTOM_TOOLS: { enabled: false },
}

export const experimentDefault = Object.fromEntries(
	Object.entries(experimentConfigsMap).map(([_, config]) => [
		EXPERIMENT_IDS[_ as keyof typeof EXPERIMENT_IDS] as ExperimentId,
		config.enabled,
	]),
) as Record<ExperimentId, boolean>

export const experiments = {
	get: (id: ExperimentKey): ExperimentConfig | undefined => experimentConfigsMap[id],
	isEnabled: (experimentsConfig: Experiments, id: ExperimentId) => experimentsConfig[id] ?? experimentDefault[id],
} as const
