// Временная заглушка для MMKV, пока мы чиним нативную часть
class MockMMKV {
  private data: Record<string, any> = {};
  set(key: string, value: any) { this.data[key] = value; }
  getString(key: string) { return this.data[key]; }
  getBoolean(key: string) { return !!this.data[key]; }
  delete(key: string) { delete this.data[key]; }
  clearAll() { this.data = {}; }
}

// Пытаемся импортировать настоящую MMKV, если не выйдет - используем заглушку
let storageInstance: any;
try {
  const { MMKV } = require('react-native-mmkv');
  storageInstance = new MMKV();
  console.log('MMKV: Native module loaded');
} catch (e) {
  console.warn('MMKV: Failed to load native module, using Mock.', e);
  storageInstance = new MockMMKV();
}

export const storage = storageInstance;

export const mmkvStorage = {
  setItem(key: string, value: string): void {
    storage.set(key, value);
  },
  getItem(key: string): string | null {
    return storage.getString(key) ?? null;
  },
  removeItem(key: string): void {
    storage.delete(key);
  },
  clearAll(): void {
    storage.clearAll();
  }
};
