import type { UserPreferenceFields } from '../../users/src';

/**
 * Precedence: trip override > persistent user preference > application default.
 * Merges field-by-field so an override touching only one field never masks the
 * caller's other persisted preferences.
 */
export function resolveEffectivePreference(
  override: Partial<UserPreferenceFields> | undefined,
  userPreference: UserPreferenceFields | undefined,
  appDefault: UserPreferenceFields,
): UserPreferenceFields {
  return { ...appDefault, ...userPreference, ...override };
}
