import { readFileSync, existsSync } from 'fs' import path from 'path' import { atomicWriteJSON } from './file-utils' export interface ItemOverride { hidden?: boolean categoryOverride?: string categoryLabelOverride?: string sortOrder?: number showColors?: boolean hiddenModifierIds?: string[] hiddenVariationIds?: string[] descriptionOverride?: string /** Per-modifier minimum selections override. Key = modifier list ID, value = min count. */ modifierMinSelected?: Record /** Minimum latex colors the customer must pick (default 1 when showColors=true). */ colorMin?: number /** Maximum latex colors the customer can pick (null = unlimited). */ colorMax?: number /** Extra charge in cents added per chrome color selected (0 = no per-color surcharge). */ chromeSurchargePerColor?: number /** Unit label for the quantity field, e.g. "ft". When set, the quantity control shows "X ft". */ quantityUnit?: string } export type OverridesMap = Record const OVERRIDES_PATH = path.join(process.cwd(), 'data', 'item-overrides.json') export function readOverrides(): OverridesMap { if (!existsSync(OVERRIDES_PATH)) return {} try { return JSON.parse(readFileSync(OVERRIDES_PATH, 'utf-8')) } catch { return {} } } export function writeOverrides(overrides: OverridesMap): void { atomicWriteJSON(OVERRIDES_PATH, overrides) } export function setOverride(itemId: string, patch: Partial): void { const all = readOverrides() all[itemId] = { ...(all[itemId] ?? {}), ...patch } writeOverrides(all) } export function clearOverride(itemId: string): void { const all = readOverrides() delete all[itemId] writeOverrides(all) }