export const ACCOUNT_MOSAIC_STORAGE_KEY = "codexRemote.accountMosaic";
export const CONVERSATION_ACCOUNT_VISIBLE_STORAGE_KEY = "codexRemote.conversationAccountVisible";

export function readAccountMosaicPreference(storage = globalThis.localStorage) {
  try {
    return storage?.getItem(ACCOUNT_MOSAIC_STORAGE_KEY) === "true";
  } catch {
    return false;
  }
}

export function writeAccountMosaicPreference(storage = globalThis.localStorage, enabled = false) {
  try {
    storage?.setItem(ACCOUNT_MOSAIC_STORAGE_KEY, String(Boolean(enabled)));
  } catch {
    // Storage may be unavailable in hardened browser contexts; the in-memory choice still works.
  }
}

export function readConversationAccountVisibilityPreference(storage = globalThis.localStorage) {
  try {
    return storage?.getItem(CONVERSATION_ACCOUNT_VISIBLE_STORAGE_KEY) !== "false";
  } catch {
    return true;
  }
}

export function writeConversationAccountVisibilityPreference(storage = globalThis.localStorage, visible = true) {
  try {
    storage?.setItem(CONVERSATION_ACCOUNT_VISIBLE_STORAGE_KEY, String(Boolean(visible)));
  } catch {
    // Storage may be unavailable; the in-memory choice still works for this session.
  }
}
