use rustc_hash::FxHashMap;
use serde::Serialize;

use crate::data::{POIData, PropertyData};
use crate::grid_index::GridIndex;

#[derive(Serialize, Clone)]
pub struct POICategoryGroup {
    pub name: String,
    pub categories: Vec<String>,
}

pub struct AppState {
    pub data: PropertyData,
    pub grid: GridIndex,
    /// h3_cells[row_idx] = precomputed H3 cell ID at max resolution (12).
    /// Parent cells for lower resolutions derived via CellIndex::parent().
    pub h3_cells: Vec<u64>,
    pub poi_data: POIData,
    pub poi_grid: GridIndex,
    /// Precomputed JSON key names: "min_{feature_name}" for each numeric feature
    pub min_keys: Vec<String>,
    /// Precomputed JSON key names: "max_{feature_name}" for each numeric feature
    pub max_keys: Vec<String>,
    /// Precomputed JSON key names: "min_{enum_name}" for each enum feature
    pub enum_min_keys: Vec<String>,
    /// Precomputed JSON key names: "max_{enum_name}" for each enum feature
    pub enum_max_keys: Vec<String>,
    /// Precomputed POI category groups (sorted)
    pub poi_category_groups: Vec<POICategoryGroup>,
    /// Precomputed map from enum feature name to index in data.enum_features
    pub enum_name_to_idx: FxHashMap<String, usize>,
    /// URL of the OG screenshot sidecar service (e.g. http://og-screenshot:8002)
    pub og_sidecar_url: Option<String>,
    /// Public-facing URL for absolute og:image URLs (e.g. https://narrowit.schmelczer.dev)
    pub public_url: String,
    /// Contents of index.html read at startup, used for crawler OG injection
    pub index_html: Option<String>,
    /// Shared HTTP client for proxying to the screenshot sidecar
    pub http_client: reqwest::Client,
}
