/**
 * eTerra layer catalog — all known layers grouped by category.
 */

import type { LayerConfig } from "./eterra-client";

export type LayerCategory =
  | "terenuri"
  | "documentatii"
  | "cladiri"
  | "administrativ";

export type LayerCatalogItem = LayerConfig & {
  label: string;
  category: LayerCategory;
};

export const LAYER_CATEGORY_LABELS: Record<LayerCategory, string> = {
  terenuri: "Terenuri",
  documentatii: "Documentații",
  cladiri: "Clădiri",
  administrativ: "Administrativ",
};

export const LAYER_CATALOG: LayerCatalogItem[] = [
  // ── Terenuri ──
  {
    id: "TERENURI_ACTIVE",
    name: "TERENURI_ACTIVE",
    label: "Terenuri active",
    category: "terenuri",
    endpoint: "aut",
    whereTemplate: "{{adminField}}={{siruta}} AND IS_ACTIVE=1",
  },
  {
    id: "TERENURI_NEINREGISTRATE",
    name: "TERENURI_NEINREGISTRATE",
    label: "Terenuri neînregistrate",
    category: "terenuri",
    endpoint: "aut",
  },
  {
    id: "TERENURI_IN_LUCRU",
    name: "TERENURI_IN_LUCRU",
    label: "Terenuri în lucru",
    category: "terenuri",
    endpoint: "aut",
  },
  {
    id: "TERENURI_RECEPTIONATE",
    name: "TERENURI_RECEPTIONATE",
    label: "Terenuri recepționate",
    category: "terenuri",
    endpoint: "aut",
  },
  {
    id: "TERENURI_RESPINSE",
    name: "TERENURI_RESPINSE",
    label: "Terenuri respinse",
    category: "terenuri",
    endpoint: "aut",
  },
  {
    id: "TERENURI_PE_CERERE",
    name: "TERENURI_PE_CERERE",
    label: "Terenuri pe cerere",
    category: "terenuri",
    endpoint: "aut",
  },
  {
    id: "CADGEN_LAND_ACTIVE",
    name: "CADGEN_LAND_ACTIVE",
    label: "Cadgen land active",
    category: "terenuri",
    endpoint: "aut",
  },

  // ── Clădiri ──
  {
    id: "CLADIRI_ACTIVE",
    name: "CLADIRI_ACTIVE",
    label: "Clădiri active",
    category: "cladiri",
    endpoint: "aut",
  },
  {
    id: "CLADIRI_RECEPTIONATE",
    name: "CLADIRI_RECEPTIONATE",
    label: "Clădiri recepționate",
    category: "cladiri",
    endpoint: "aut",
  },
  {
    id: "CLADIRI_RESPINSE",
    name: "CLADIRI_RESPINSE",
    label: "Clădiri respinse",
    category: "cladiri",
    endpoint: "aut",
  },
  {
    id: "CLADIRI_PE_CERERE",
    name: "CLADIRI_PE_CERERE",
    label: "Clădiri pe cerere",
    category: "cladiri",
    endpoint: "aut",
  },
  {
    id: "CLADIRI_IN_LUCRU",
    name: "CLADIRI_IN_LUCRU",
    label: "Clădiri în lucru",
    category: "cladiri",
    endpoint: "aut",
  },
  {
    id: "CLADIRI_NEINREGISTRATE",
    name: "CLADIRI_NEINREGISTRATE",
    label: "Clădiri neînregistrate",
    category: "cladiri",
    endpoint: "aut",
  },
  {
    id: "CADGEN_BUILDING_ACTIVE",
    name: "CADGEN_BUILDING_ACTIVE",
    label: "Cadgen building active",
    category: "cladiri",
    endpoint: "aut",
  },

  // ── Documentații ──
  {
    id: "EXPERTIZA_CLADIRI_ACTIVE_DYNAMIC",
    name: "EXPERTIZA_CLADIRI_ACTIVE_DYNAMIC",
    label: "Expertiză clădiri active",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "EXPERTIZA_CLADIRI_INACTIVE_DYNAMIC",
    name: "EXPERTIZA_CLADIRI_INACTIVE_DYNAMIC",
    label: "Expertiză clădiri inactive",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "EXPERTIZA_TERENURI_ACTIVE_DYNAMIC",
    name: "EXPERTIZA_TERENURI_ACTIVE_DYNAMIC",
    label: "Expertiză terenuri active",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "EXPERTIZA_TERENURI_INACTIVE_DYNAMIC",
    name: "EXPERTIZA_TERENURI_INACTIVE_DYNAMIC",
    label: "Expertiză terenuri inactive",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "EXPERTIZA_JUDICIARA_ADMISE_DYNAMIC",
    name: "EXPERTIZA_JUDICIARA_ADMISE_DYNAMIC",
    label: "Expertiză judiciară admise",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "EXPERTIZA_JUDICIARA_RESPINSE_DYNAMIC",
    name: "EXPERTIZA_JUDICIARA_RESPINSE_DYNAMIC",
    label: "Expertiză judiciară respinse",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "EXPERTIZA_JUDICIARA_NEINREGISTRATE_DYNAMIC",
    name: "EXPERTIZA_JUDICIARA_NEINREGISTRATE_DYNAMIC",
    label: "Expertiză judiciară neînreg.",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "ZONE_INTERES_ACTIVE_DYNAMIC",
    name: "ZONE_INTERES_ACTIVE_DYNAMIC",
    label: "Zone interes active",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "ZONE_INTERES_INACTIVE_DYNAMIC",
    name: "ZONE_INTERES_INACTIVE_DYNAMIC",
    label: "Zone interes inactive",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "ZONE_INTERES_PROPUSE_DYNAMIC",
    name: "ZONE_INTERES_PROPUSE_DYNAMIC",
    label: "Zone interes propuse",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "RECEPTII_TEHNICE_ADMISE_DYNAMIC",
    name: "RECEPTII_TEHNICE_ADMISE_DYNAMIC",
    label: "Recepții tehnice admise",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "RECEPTII_TEHNICE_RESPINSE_DYNAMIC",
    name: "RECEPTII_TEHNICE_RESPINSE_DYNAMIC",
    label: "Recepții tehnice respinse",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "RECEPTII_TEHNICE_NEINREGISTRATE_DYNAMIC",
    name: "RECEPTII_TEHNICE_NEINREGISTRATE_DYNAMIC",
    label: "Recepții tehnice neînreg.",
    category: "documentatii",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },

  // ── Administrativ ──
  {
    id: "LIMITE_UAT",
    name: "LIMITE_UAT",
    label: "Limite UAT",
    category: "administrativ",
    endpoint: "all",
  },
  {
    id: "LIMITE_INTRAV_DYNAMIC",
    name: "LIMITE_INTRAV_DYNAMIC",
    label: "Limite intravilan",
    category: "administrativ",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "SPECIAL_AREAS_ACTIVE_DYNAMIC",
    name: "SPECIAL_AREAS_ACTIVE_DYNAMIC",
    label: "Arii speciale active",
    category: "administrativ",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
  {
    id: "SPECIAL_AREAS_INACTIVE_DYNAMIC",
    name: "SPECIAL_AREAS_INACTIVE_DYNAMIC",
    label: "Arii speciale inactive",
    category: "administrativ",
    endpoint: "aut",
    spatialFilter: true,
    subLayerId: 0,
  },
];

export const findLayerById = (id?: string) =>
  LAYER_CATALOG.find((l) => l.id === id);
