const STORAGE_PREFIX = 'smt_'

export const storage = {
	set(key, value) {
		try {
			uni.setStorageSync(STORAGE_PREFIX + key, JSON.stringify(value))
		} catch (e) {
			console.error('Storage set error:', e)
		}
	},

	get(key, defaultValue = null) {
		try {
			const value = uni.getStorageSync(STORAGE_PREFIX + key)
			return value ? JSON.parse(value) : defaultValue
		} catch (e) {
			console.error('Storage get error:', e)
			return defaultValue
		}
	},

	remove(key) {
		try {
			uni.removeStorageSync(STORAGE_PREFIX + key)
		} catch (e) {
			console.error('Storage remove error:', e)
		}
	},

	clear() {
		try {
			uni.clearStorageSync()
		} catch (e) {
			console.error('Storage clear error:', e)
		}
	}
}

export const SESSION_KEY = 'session_key'
export const USER_KEY = 'user'
export const PROFILE_KEY = 'profile'
