import AsyncStorage from '@react-native-async-storage/async-storage';

const PROFILE_KEY = 'nova40_profile';

/**
 * Get user profile data.
 * @param {string} userId
 */
export async function getProfile(userId) {
  const raw = await AsyncStorage.getItem(`${PROFILE_KEY}_${userId}`);
  return raw ? JSON.parse(raw) : null;
}

/**
 * Save user profile data.
 * @param {string} userId
 * @param {{ nickname?: string, fullName?: string, photoUri?: string }} data
 */
export async function saveProfile(userId, data) {
  const existing = await getProfile(userId) || {};
  const updated = { ...existing, ...data, updatedAt: new Date().toISOString() };
  await AsyncStorage.setItem(`${PROFILE_KEY}_${userId}`, JSON.stringify(updated));
  return updated;
}
