import { type Config, type NotificationConfig, resolveConfig, resolveNotificationConfig } from './config.ts';
import { Query } from './query.ts';
import { Notification } from './notification.ts';


/**
 * Initialization for interacting with the Elevate Storefront API
 * @see https://docs.elevate.voyado.cloud/elevate/4/integration/api/specifications/storefront/v3/
 */
export function elevate(config: Config) {
  const resolvedConfig = resolveConfig(config);

  return Object.freeze({
    /** The base URL to the Elevate cluster hosting the API */
    clusterUrl: resolvedConfig.clusterUrl,
    /** Send queries to retrieve products, facets and more */
    query: new Query(resolvedConfig),
    /** Send notifications for clicks, add-to-carts and more */
    notify: new Notification(resolvedConfig)
  });
}

/**
 * @deprecated eSales has changed name to Elevate.
 * @see https://docs.elevate.voyado.cloud/elevate/4/changelog/#esales-is-voyado-elevate
 */
export const esales = elevate;

/**
 * Initialization for interacting with the Elevate Storefront Queries API
 * @see https://docs.elevate.voyado.cloud/elevate/4/integration/api/specifications/storefront/v3/
 */
export function queries(config: Config) {
  return new Query(resolveConfig(config));
}

/**
 * Initialization for interacting with the Elevate Storefront Notifications API
 * @see https://docs.elevate.voyado.cloud/elevate/4/integration/api/specifications/storefront/v3/
 */
export function notifications(config: NotificationConfig) {
  return new Notification(resolveNotificationConfig(config));
}


// Export Typescript interfaces/types
export * from './models/mod.ts';
export type { Config, NotificationConfig, Session, SessionMetadata, Touchpoint } from './config.ts';

// Helper functions
export * from './helpers/mod.ts';
export { type LocalStorageSession, localStorageBackedSession } from './session.ts';
