/**
 * Web platform session persistence using localStorage.
 * Returns Promises to match the Electron IPC-based API contract.
 */
const SESSION_KEY = 'discord-clone-session';

export default {
  save(data) {
    try {
      localStorage.setItem(SESSION_KEY, JSON.stringify(data));
      return Promise.resolve(true);
    } catch {
      return Promise.resolve(false);
    }
  },

  load() {
    try {
      const raw = localStorage.getItem(SESSION_KEY);
      return Promise.resolve(raw ? JSON.parse(raw) : null);
    } catch {
      return Promise.resolve(null);
    }
  },

  clear() {
    try {
      localStorage.removeItem(SESSION_KEY);
      return Promise.resolve(true);
    } catch {
      return Promise.resolve(false);
    }
  },
};
