export const OVERLAY_IDS = [
  'noise',
  'crime-hotspots',
  'trees-outside-woodlands',
  'property-borders',
] as const;

export type OverlayId = (typeof OVERLAY_IDS)[number];

export interface OverlayDefinition {
  id: OverlayId;
  label: string;
  description: string;
  detail: string;
  /** Enabled on a fresh visit (no `overlay` URL params). */
  defaultEnabled?: boolean;
}

export const OVERLAYS: OverlayDefinition[] = [
  {
    id: 'noise',
    label: 'Noise',
    description: 'High-resolution Defra Lden noise raster',
    detail:
      'Defra Strategic Noise Mapping Round 4 (2022), combining road, rail, and airport sources. Values are the EU-standard Lden metric (day-evening-night 24-hour weighted average), modelled on a 10m grid at 4m above ground. Brighter areas indicate higher modelled noise. Licensed under the Open Government Licence v3.0.',
  },
  {
    id: 'crime-hotspots',
    label: 'Crime hotspots',
    description: 'Approximate police.uk street-crime heatmap',
    detail:
      'Client-side heatmap of street-level crimes published by police.uk over the most recent months. Police.uk coordinates are anonymised snap-to-grid points, not exact offence locations, so the heatmap should be read as an approximation of relative density rather than a precise map of incidents.',
    defaultEnabled: true,
  },
  {
    id: 'trees-outside-woodlands',
    label: 'Trees & woodland',
    description: 'Tree canopy and woodland polygons',
    detail:
      'Forest Research Trees Outside Woodland (TOW) v1 canopy polygons — lone trees and groups of trees — unioned with National Forest Inventory (NFI) woodland blocks (≥0.5 ha) that TOW deliberately excludes. Together they cover both street trees and actual woods. Polygon opacity scales with canopy area.',
    defaultEnabled: true,
  },
  {
    id: 'property-borders',
    label: 'Property borders',
    description: 'Individual freehold property/land-parcel boundaries',
    detail:
      'HM Land Registry INSPIRE Index Polygons — the position and indicative extent of freehold registered property in England & Wales, drawn as outlines at street level. These are "general boundaries" for guidance only, not the precise legal boundary of a property, and they exclude leasehold-only interests and unregistered land (roughly 85–90% of freehold land is covered). This information is subject to Crown copyright and database rights 2026 and is reproduced with the permission of HM Land Registry. The polygons (including the associated geometry, namely x, y co-ordinates) are subject to Crown copyright and database rights 2026 Ordnance Survey AC0000851063. Licensed under the Open Government Licence v3.0.',
  },
];

/** Overlays shown on a fresh visit, before any `overlay` URL params apply. */
export const DEFAULT_OVERLAY_IDS: OverlayId[] = OVERLAYS.filter((o) => o.defaultEnabled).map(
  (o) => o.id
);

const OVERLAY_ID_SET = new Set<string>(OVERLAY_IDS);

export function isOverlayId(value: string): value is OverlayId {
  return OVERLAY_ID_SET.has(value);
}

/**
 * Lowest zoom at which each overlay's tiles are generated by the pipeline
 * (see the `--min-zoom` defaults in pipeline/transform/*_tiles.py). Used as
 * the tile source's `minzoom` so we don't request tiles that don't exist —
 * this is a data-availability floor, NOT the visibility limit. The limit at
 * which overlays (and postcodes) start showing is the shared
 * POSTCODE_ZOOM_THRESHOLD.
 */
export const OVERLAY_MIN_ZOOM: Record<OverlayId, number> = {
  'crime-hotspots': 12,
  noise: 12,
  'property-borders': 12,
  'trees-outside-woodlands': 12,
};
