/**
 * 存储管理工具
 */

const STORAGE_PREFIX = 'aimz_';

// 获取完整的存储键名
const getFullKey = (key) => {
	return `${STORAGE_PREFIX}${key}`;
};

// 设置存储
export const set = (key, data) => {
	try {
		const fullKey = getFullKey(key);
		uni.setStorageSync(fullKey, data);
		return true;
	} catch (error) {
		console.error('Storage set error:', error);
		return false;
	}
};

// 获取存储
export const get = (key, defaultValue = null) => {
	try {
		const fullKey = getFullKey(key);
		const value = uni.getStorageSync(fullKey);
		return value || defaultValue;
	} catch (error) {
		console.error('Storage get error:', error);
		return defaultValue;
	}
};

// 移除存储
export const remove = (key) => {
	try {
		const fullKey = getFullKey(key);
		uni.removeStorageSync(fullKey);
		return true;
	} catch (error) {
		console.error('Storage remove error:', error);
		return false;
	}
};

// 清除所有存储
export const clear = () => {
	try {
		uni.clearStorageSync();
		return true;
	} catch (error) {
		console.error('Storage clear error:', error);
		return false;
	}
};

// 获取存储信息
export const info = () => {
	try {
		return uni.getStorageInfoSync();
	} catch (error) {
		console.error('Storage info error:', error);
		return null;
	}
};