/**
 * Storage API runtime configuration.
 *
 * Additive registration — mirrors core/api/runtime.js:
 *   registerStoragePolicies(policies)       called by features during initializeZen()
 *   registerStoragePublicPrefixes(prefixes) called by features during initializeZen()
 *   clearStorageConfig()                    called by resetZenInitialization() / tests
 *
 * getStorageAccessPolicies() and getStoragePublicPrefixes() are read-only readers
 * used internally by api.js — they are not re-exported from index.js.
 */

const POLICIES_KEY = Symbol.for('__ZEN_STORAGE_POLICIES__');
const PREFIXES_KEY = Symbol.for('__ZEN_STORAGE_PUBLIC_PREFIXES__');

if (!globalThis[POLICIES_KEY]) globalThis[POLICIES_KEY] = [];
if (!globalThis[PREFIXES_KEY]) globalThis[PREFIXES_KEY] = [];

export function registerStoragePolicies(policies) {
  if (!Array.isArray(policies)) {
    throw new TypeError('registerStoragePolicies: policies must be an array');
  }
  globalThis[POLICIES_KEY].push(...policies);
}

export function registerStoragePublicPrefixes(prefixes) {
  if (!Array.isArray(prefixes)) {
    throw new TypeError('registerStoragePublicPrefixes: prefixes must be an array');
  }
  globalThis[PREFIXES_KEY].push(...prefixes);
}

export function clearStorageConfig() {
  globalThis[POLICIES_KEY].length = 0;
  globalThis[PREFIXES_KEY].length = 0;
}

export function getStoragePublicPrefixes() {
  return globalThis[PREFIXES_KEY];
}

export function getStorageAccessPolicies() {
  return globalThis[POLICIES_KEY];
}
