import { OnboardingProfileDb } from './database'; export type PersistentOnboardingStep = 'lexicon' | 'customize' | 'scan' | 'reminder' | 'collection'; const STEP_COLUMN: Record = { lexicon: 'lexicon_explored', customize: 'customization_done', scan: 'scan_done', reminder: 'reminder_done', collection: 'collection_done', }; const STEP_SETTER: Record void> = { lexicon: OnboardingProfileDb.setLexiconExplored, customize: OnboardingProfileDb.setCustomizationDone, scan: OnboardingProfileDb.setScanDone, reminder: OnboardingProfileDb.setReminderDone, collection: OnboardingProfileDb.setCollectionDone, }; export const OnboardingProgressService = { isStepCompleted(userId: number, step: PersistentOnboardingStep): boolean { const profile = OnboardingProfileDb.get(userId); return profile[STEP_COLUMN[step]] === 1; }, completeStep(userId: number, step: PersistentOnboardingStep): void { STEP_SETTER[step](userId, true); }, getSignals(userId: number) { const profile = OnboardingProfileDb.get(userId); return { lexiconExplored: profile.lexicon_explored === 1, customizationDone: profile.customization_done === 1, scanDone: profile.scan_done === 1, reminderDone: profile.reminder_done === 1, collectionDone: profile.collection_done === 1, }; }, getAcquisitionSource(userId: number): string | null { return OnboardingProfileDb.get(userId).acquisition_source; }, setAcquisitionSource(userId: number, source: string): void { OnboardingProfileDb.setAcquisitionSource(userId, source); }, setPrimaryGoal(userId: number, goal: string): void { OnboardingProfileDb.setPrimaryGoal(userId, goal); }, setExperienceLevel(userId: number, level: string): void { OnboardingProfileDb.setExperienceLevel(userId, level); }, };