/**
 * Geoportal module types.
 */

/** Martin vector tile source definition */
export type MartinSource = {
  id: string;
  /** Human-readable label (Romanian) */
  label: string;
  /** Martin source name (matches PostGIS table/view) */
  sourceName: string;
  /** Minimum zoom level for visibility */
  minZoom: number;
  /** Maximum zoom level for visibility */
  maxZoom: number;
  /** Whether layer is visible by default */
  defaultVisible: boolean;
};

/** Layer style configuration */
export type LayerStyle = {
  fillColor: string;
  fillOpacity: number;
  lineColor: string;
  lineWidth: number;
};

/** Feature attributes from a clicked map feature */
export type ClickedFeature = {
  layerId: string;
  sourceLayer: string;
  properties: Record<string, unknown>;
  coordinates: [number, number];
};

/** Layer visibility state */
export type LayerVisibility = Record<string, boolean>;

/** Map view state */
export type MapViewState = {
  center: [number, number];
  zoom: number;
};

/* ------------------------------------------------------------------ */
/*  Basemap                                                            */
/* ------------------------------------------------------------------ */

export type BasemapId = "liberty" | "dark" | "satellite" | "google" | "orto";

export type BasemapDef = {
  id: BasemapId;
  label: string;
  tiles: string[];
  attribution: string;
  tileSize?: number;
  maxzoom?: number;
};

/* ------------------------------------------------------------------ */
/*  Selection                                                          */
/* ------------------------------------------------------------------ */

export type SelectedFeature = {
  id: string; // objectId or composite key
  sourceLayer: string;
  properties: Record<string, unknown>;
};

/* ------------------------------------------------------------------ */
/*  Search                                                             */
/* ------------------------------------------------------------------ */

export type SearchResult = {
  id: string;
  type: "parcel" | "uat" | "building";
  label: string;
  sublabel?: string;
  coordinates?: [number, number]; // lng, lat for flyTo
  bbox?: [number, number, number, number];
  properties?: Record<string, unknown>;
};

/* ------------------------------------------------------------------ */
/*  Feature info (enrichment from ParcelSync)                          */
/* ------------------------------------------------------------------ */

export type FeatureDetail = {
  id: string;
  layerId: string;
  siruta: string;
  objectId: number;
  cadastralRef: string | null;
  areaValue: number | null;
  enrichment: FeatureEnrichmentData | null;
  enrichedAt: string | null;
};

export type FeatureEnrichmentData = {
  NR_CAD: string;
  NR_CF: string;
  NR_CF_VECHI: string;
  NR_TOPO: string;
  ADRESA: string;
  PROPRIETARI: string;
  PROPRIETARI_VECHI: string;
  SUPRAFATA_2D: number | string;
  SUPRAFATA_R: number | string;
  SOLICITANT: string;
  INTRAVILAN: string;
  CATEGORIE_FOLOSINTA: string;
  HAS_BUILDING: number;
  BUILD_LEGAL: number;
};

/* ------------------------------------------------------------------ */
/*  Export                                                              */
/* ------------------------------------------------------------------ */

export type ExportFormat = "dxf" | "gpkg";
