import AsyncStorage from '@react-native-async-storage/async-storage'; import { OnboardingProgressService } from './onboardingProgressService'; const STORAGE_KEY = 'greenlens_preauth_onboarding_v1'; export type PreAuthAnswers = { acquisitionSource?: string; primaryGoal?: string; experienceLevel?: string; lightLevel?: string; }; export const PreAuthOnboardingService = { async setAnswer(key: K, value: PreAuthAnswers[K]): Promise { const answers = await this.getAnswers(); answers[key] = value; await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(answers)); }, async getAnswers(): Promise { try { const raw = await AsyncStorage.getItem(STORAGE_KEY); return raw ? (JSON.parse(raw) as PreAuthAnswers) : {}; } catch { return {}; } }, // Persist buffered answers into the per-user profile after sign-up/login. async flushToProfile(userId: number): Promise { const answers = await this.getAnswers(); if (answers.acquisitionSource) OnboardingProgressService.setAcquisitionSource(userId, answers.acquisitionSource); if (answers.primaryGoal) OnboardingProgressService.setPrimaryGoal(userId, answers.primaryGoal); if (answers.experienceLevel) OnboardingProgressService.setExperienceLevel(userId, answers.experienceLevel); await AsyncStorage.removeItem(STORAGE_KEY); }, };