import { appConfig } from "$config/index.js";

const normalizeNationalCode = (value = "") => String(value).trim();

export const getAllowedTestNationalCodes = () =>
  appConfig.testNationalCodes
    .map(normalizeNationalCode)
    .filter(Boolean);

export const isTestModeEnabled = () => appConfig.testMode;

export const isTestNationalCodeAllowed = (nationalCode) => {
  if (!isTestModeEnabled()) {
    return true;
  }

  const normalizedNationalCode = normalizeNationalCode(nationalCode);

  if (!normalizedNationalCode) {
    return false;
  }

  return getAllowedTestNationalCodes().includes(normalizedNationalCode);
};
