export interface FeatureMeta {
  name: string;
  type: 'numeric' | 'enum';
  group?: string;
  // Numeric-only fields
  min?: number;
  max?: number;
  step?: number;
  histogram?: { min: number; max: number; bin_width: number; counts: number[] };
  // Enum-only fields
  values?: string[];
  // Description fields
  description?: string;
  detail?: string;
  source?: string;
}

export interface FeatureGroup {
  name: string;
  features: FeatureMeta[];
}

// Filters: feature name -> [selectedMin, selectedMax] for numeric, string[] for enum
export type FeatureFilters = Record<string, [number, number] | string[]>;

export interface HexagonData {
  h3: string;
  count: number;
  [key: string]: string | number | null;
}

export interface Bounds {
  south: number;
  west: number;
  north: number;
  east: number;
}

export interface ViewState {
  longitude: number;
  latitude: number;
  zoom: number;
  pitch: number;
  bearing?: number;
}

export interface ViewChangeParams {
  resolution: number;
  bounds: Bounds;
  zoom: number;
  latitude: number;
  longitude: number;
}

export interface ApiResponse {
  features: HexagonData[];
}

export interface POI {
  id: string;
  name: string;
  category: string;
  group: string;
  lat: number;
  lng: number;
  emoji: string;
}

export interface POIResponse {
  pois: POI[];
}

export interface POICategoryGroup {
  name: string;
  categories: string[];
}

export interface POICategoriesResponse {
  groups: POICategoryGroup[];
}

export interface Property {
  // String fields
  address?: string;
  postcode?: string;
  property_type?: string;
  built_form?: string;
  duration?: string;
  current_energy_rating?: string;
  potential_energy_rating?: string;

  // Numeric fields
  lat: number;
  lon: number;

  is_construction_date_approximate?: boolean;

  // All other numeric features (dynamic, including construction_age_band)
  [key: string]: string | number | boolean | undefined;
}

export interface HexagonPropertiesResponse {
  properties: Property[];
  total: number;
  limit: number;
  offset: number;
  truncated: boolean;
}

export interface NumericFeatureStats {
  name: string;
  count: number;
  min: number;
  max: number;
  mean: number;
  histogram: { min: number; max: number; bin_width: number; counts: number[] };
}

export interface EnumFeatureStats {
  name: string;
  counts: Record<string, number>;
}

export interface HexagonStatsResponse {
  count: number;
  numeric_features: NumericFeatureStats[];
  enum_features: EnumFeatureStats[];
}
