// Server-side feature flag for the api.gis.ac cutover (Plan 003, Faza C).
//
// Off by default → all parcel/eterra/geoportal call sites keep using the
// legacy local-DB code path. Flip via Infisical /architools:
//   USE_GIS_AC=1                    → global enable
//   GIS_AC_PILOT_USERS=a@x,b@y      → per-email override for staged rollout
//
// After redeploy, call sites read useGisAcFlag(session.user.email) and
// branch between the legacy path and the gis-api thin client (Faza D).

const PILOT_USERS = (process.env.GIS_AC_PILOT_USERS || "")
  .split(",")
  .map((s) => s.trim().toLowerCase())
  .filter(Boolean);

export function useGisAcFlag(userEmail?: string | null): boolean {
  if (process.env.USE_GIS_AC === "1") return true;
  if (!userEmail) return false;
  return PILOT_USERS.includes(userEmail.toLowerCase());
}
