import type { StorefrontInstance } from 'storefrontSdkV1';
import type { StorefrontInstanceV2 } from '../connector/index';

export function checkStorefrontSdkMethod(
  client: StorefrontInstance | StorefrontInstanceV2,
  methodName: 'content' | 'navigation' | 'products' | 'spaceProperties'
): void {
  if (typeof (client as StorefrontInstance)[methodName] === 'undefined') {
    throw new Error(
      `The provided 'params.client' does not have a '${methodName}' method. If using @nacelle/storefront-sdk@2.x major version 2, be sure to initialize the client with the Commerce Queries plugin before passing it to @nacelle/compatibility-connector.`
    );
  }
}
