// import RNDeviceInfo from 'react-native-device-info';
import * as fs from 'expo-file-system/legacy';

import { createMMKV, MMKV } from 'react-native-mmkv';

function fixPath(path: string) {
    if (path.startsWith("file:///")) {
        return path.substring(7);
    }
    if (path.startsWith("file:/")) {
        return path.replace(/^file:\//, "/");
    }
}
let globalStorage: MMKV | null = null;
export function getGlobalStorage() {
    if (!globalStorage) {
        globalStorage = createMMKV({
            id: `global`,
            path: fixPath(fs.cacheDirectory??''),
        });
    }
    return globalStorage;
}

let caches: MMKV | null = null;
export function getCaches() {
    if (!caches) {
        caches = createMMKV({
            id: `caches`,
            path: fixPath(fs.cacheDirectory??''),
        });
    }
    return caches;
}

let apiCache: MMKV | null = null;
export function getApiCache() {
    if (!apiCache) {
        apiCache = createMMKV({
            id: `api_cache`,
            path: fixPath(fs.cacheDirectory??''),
        });
    }
    return apiCache;
}