1/**
 2 * Type-safe configuration helpers
 3 *
 4 * Provides utilities for safely accessing and modifying configuration objects
 5 * with dynamic keys while maintaining TypeScript type safety.
 6 */
 7
 8/**
 9 * Type-safe helper to access config properties dynamically
10 * Provides better type safety than direct casting to Record
11 */
12export function setConfigValue<T extends SettingsConfigType>(
13	config: T,
14	key: string,
15	value: unknown
16): void {
17	if (key in config) {
18		(config as Record<string, unknown>)[key] = value;
19	}
20}
21
22/**
23 * Type-safe helper to get config values dynamically
24 */
25export function getConfigValue<T extends SettingsConfigType>(
26	config: T,
27	key: string
28): string | number | boolean | undefined {
29	const value = (config as Record<string, unknown>)[key];
30	return value as string | number | boolean | undefined;
31}
32
33/**
34 * Convert a SettingsConfigType to a ParameterRecord for specific keys
35 * Useful for parameter synchronization operations
36 */
37export function configToParameterRecord<T extends SettingsConfigType>(
38	config: T,
39	keys: string[]
40): Record<string, string | number | boolean> {
41	const record: Record<string, string | number | boolean> = {};
42
43	for (const key of keys) {
44		const value = getConfigValue(config, key);
45		if (value !== undefined) {
46			record[key] = value;
47		}
48	}
49
50	return record;
51}