"""GIBS API endpoints, EPSG codes, and TileMatrixSet definitions."""

from mcgibs import __version__ as _version

# GIBS base URLs — domain sharding (gibs-a/b/c) for parallel tile fetches
WMTS_BASE = "https://gibs.earthdata.nasa.gov/wmts/epsg{epsg}/best"
WMS_BASE = "https://gibs.earthdata.nasa.gov/wms/epsg{epsg}/best/wms.cgi"
COLORMAP_BASE = "https://gibs.earthdata.nasa.gov/colormaps/v1.3"
LAYER_METADATA_BASE = "https://gibs.earthdata.nasa.gov/layer-metadata/v1.0"

# GetCapabilities and DescribeDomains
WMTS_CAPABILITIES_URL = WMTS_BASE + "/1.0.0/WMTSCapabilities.xml"
WMTS_DESCRIBE_DOMAINS_URL = (
    WMTS_BASE + "/wmts.cgi?SERVICE=WMTS&VERSION=1.0.0&REQUEST=DescribeDomains&LAYER={layer_id}"
)

# WMTS REST tile URL pattern
WMTS_TILE_URL = WMTS_BASE + "/{layer_id}/default/{date}/{tile_matrix_set}/{z}/{row}/{col}.{ext}"

# Nominatim geocoding
NOMINATIM_BASE = "https://nominatim.openstreetmap.org"

# Supported projections — EPSG code → human label
PROJECTIONS = {
    "4326": "Geographic (EPSG:4326, WGS84)",
    "3857": "Web Mercator (EPSG:3857)",
    "3413": "Arctic Polar Stereographic (EPSG:3413)",
    "3031": "Antarctic Polar Stereographic (EPSG:3031)",
}

# Default projection for most requests
DEFAULT_EPSG = "4326"

# WMTS XML namespaces used in GetCapabilities
WMTS_NS = {
    "wmts": "http://www.opengis.net/wmts/1.0",
    "ows": "http://www.opengis.net/ows/1.1",
    "xlink": "http://www.w3.org/1999/xlink",
    "gml": "http://www.opengis.net/gml",
}

# TileMatrixSet definitions for EPSG:4326
# Maps human-readable resolution names to zoom levels and pixel sizes
TILE_MATRIX_SETS_4326 = {
    "2km": {"max_zoom": 5, "tile_size": 512},
    "1km": {"max_zoom": 6, "tile_size": 512},
    "500m": {"max_zoom": 7, "tile_size": 512},
    "250m": {"max_zoom": 8, "tile_size": 512},
    "31.25m": {"max_zoom": 11, "tile_size": 512},
    "15.625m": {"max_zoom": 12, "tile_size": 512},
}

# WMS request defaults
WMS_DEFAULTS = {
    "SERVICE": "WMS",
    "VERSION": "1.1.1",
    "REQUEST": "GetMap",
    "SRS": "EPSG:4326",
    "FORMAT": "image/jpeg",
    "WIDTH": "1024",
    "HEIGHT": "1024",
}

# User-Agent for Nominatim (required by their usage policy).
# Version derived from package metadata to stay in sync with pyproject.toml.
USER_AGENT = f"mcgibs-mcp-server/{_version} (ryan@supported.systems)"
