const TOKEN_KEY = 'eintervention_public_token';
const CLIENT_KEY = 'eintervention_public_client';

export function getToken() {
  return localStorage.getItem(TOKEN_KEY) || '';
}

export function setSession(token, client) {
  localStorage.setItem(TOKEN_KEY, token);
  if (client) {
    localStorage.setItem(CLIENT_KEY, JSON.stringify(client));
  }
}

export function getStoredClient() {
  try {
    return JSON.parse(localStorage.getItem(CLIENT_KEY) || 'null');
  } catch {
    return null;
  }
}

export function updateStoredClient(client) {
  localStorage.setItem(CLIENT_KEY, JSON.stringify(client));
}

export function clearSession() {
  localStorage.removeItem(TOKEN_KEY);
  localStorage.removeItem(CLIENT_KEY);
}
