import { env } from '@/lib/env';
import { BUILD_VARIANTS, type BuildVariant } from '@/lib/constants';

const rawVariant =
  (typeof process !== "undefined"
    ? process.env.FUNNEL_BUILD_VARIANT ?? env.NEXT_PUBLIC_FUNNEL_BUILD_VARIANT
    : undefined) ?? BUILD_VARIANTS.FRONTEND;

export const BUILD_VARIANT: BuildVariant =
  rawVariant === BUILD_VARIANTS.FULL ? BUILD_VARIANTS.FULL : BUILD_VARIANTS.FRONTEND;

export const IS_FULL_SYSTEM_BUILD = BUILD_VARIANT === BUILD_VARIANTS.FULL;
export const IS_FRONTEND_ONLY_BUILD = BUILD_VARIANT === BUILD_VARIANTS.FRONTEND;

export function assertFullSystemBuild(feature?: string): void {
  if (!IS_FULL_SYSTEM_BUILD) {
    const scope = feature ? ` for ${feature}` : "";
    throw new Error(
      `This operation is only available in the full system build${scope}.`
    );
  }
}
