const DEFAULT_VENDORGET_SETTINGS = {
  consentCaptureEnabled: true,
  requestMonitoringEnabled: false
};

const VENDORGET_SETTINGS_STORAGE_KEY = "vendorgetSettings";

async function getVendorGetSettings() {
  const storedSettings = await browser.storage.local.get(
    VENDORGET_SETTINGS_STORAGE_KEY
  );

  return {
    ...DEFAULT_VENDORGET_SETTINGS,
    ...(storedSettings[VENDORGET_SETTINGS_STORAGE_KEY] ?? {})
  };
}

async function setVendorGetSetting(key, value) {
  const settings = await getVendorGetSettings();

  await browser.storage.local.set({
    [VENDORGET_SETTINGS_STORAGE_KEY]: {
      ...settings,
      [key]: value
    }
  });
}

async function isConsentCaptureEnabled() {
  return (await getVendorGetSettings()).consentCaptureEnabled;
}

async function isRequestMonitoringEnabled() {
  return (await getVendorGetSettings()).requestMonitoringEnabled;
}
