export const SettingKey = {
  Address: "vssm_api_address",
  Token: "vssm_auth_token",
} as const;

export type SettingKey = typeof SettingKey[keyof typeof SettingKey];

const SettingDefaults: Record<SettingKey, string> = {
  [SettingKey.Address]: "",
  [SettingKey.Token]: "",
};

export function getSetting(key: SettingKey): string {
  const value = localStorage.getItem(key);
  if (!value) {
    return SettingDefaults[key];
  }
  return value;
}

export function setSetting(key: SettingKey, value: string) {
  localStorage.setItem(key, value);
}

export function clearSetting(key: SettingKey) {
  localStorage.removeItem(key);
}