/**
 * When true, the geo hierarchy is served by the in-memory mock (apis/mockApi.ts) behind the
 * GeographyApi seam — canned provinces/cities/districts (incl. Tehran's 22 مناطق and the
 * white-space second-tier cities) so the cascade demos before backend-phase-4 is reachable.
 * Flip to false to hit the live `api/v1/geo/*` lookups — no hook/component changes
 * (see dev/shared-working-context/reports/mocks-registry.md).
 */
export const USE_GEOGRAPHY_MOCK = false;

/**
 * Reference data almost never changes, so it is cached **for the whole session**: an Infinite
 * `staleTime` means a province/city's children are fetched once and served from cache on every
 * revisit and across both editors (and later search). A generous `gcTime` keeps them warm even
 * after the last consumer unmounts. This is the aggressive-caching rule the phase exists to set.
 */
export const GEO_STALE_TIME = Infinity;
export const GEO_GC_TIME = 24 * 60 * 60 * 1000; // 24h

/**
 * Approximate map-pin default centre per known city, keyed by the b4 seed city ids (Tehran = 101
 * matches the real seed; the other ids match apis/seed.ts). Used only to centre the map-pin
 * picker on the chosen city; unknown cities (real data whose id we don't map) fall back to the
 * Iran centroid. Not authoritative geography — the picker emits the user's real dropped coords.
 */
export const IRAN_CENTROID = { latitude: 32.4279, longitude: 53.688 } as const;

export const CITY_CENTROIDS: Record<number, { latitude: number; longitude: number }> = {
  101: { latitude: 35.6892, longitude: 51.389 }, // Tehran
  201: { latitude: 36.2605, longitude: 59.6168 }, // Mashhad
  301: { latitude: 32.6539, longitude: 51.666 }, // Isfahan
  401: { latitude: 29.5918, longitude: 52.5837 }, // Shiraz
  501: { latitude: 38.0797, longitude: 46.2919 }, // Tabriz
  601: { latitude: 31.3183, longitude: 48.6706 }, // Ahvaz
  701: { latitude: 34.6416, longitude: 50.8746 }, // Qom
  801: { latitude: 35.8327, longitude: 50.9916 }, // Karaj
};

/** The map-pin picker centre for a city — its centroid if known, else the Iran centroid. */
export function cityCentroid(cityId?: number | null): { latitude: number; longitude: number } {
  if (cityId != null && CITY_CENTROIDS[cityId]) return CITY_CENTROIDS[cityId];
  return IRAN_CENTROID;
}
