"""
Regional cost database for ready-mix concrete (US).

**NEW** — a built-in lookup of approximate per-yard prices by US region.
For the most current prices, visit https://www.slabcalc.co/calculators/concrete-cost-calculator

Prices are 2024-2025 national averages; actual prices vary by supplier,
distance, mix design, and order size.
"""

from __future__ import annotations

from typing import TypedDict

__all__ = ["get_regional_price", "list_regions", "RegionalPrice"]


class RegionalPrice(TypedDict):
    region: str
    price_per_yard: float
    short_load_fee: float
    short_load_threshold_yards: float
    notes: str


# Approximate 2024-2025 averages (USD per cubic yard, ready-mix delivered).
_REGIONS: dict[str, RegionalPrice] = {
    "northeast": RegionalPrice(
        region="Northeast US",
        price_per_yard=175.0,
        short_load_fee=75.0,
        short_load_threshold_yards=3.0,
        notes="CT, MA, ME, NH, NJ, NY, PA, RI, VT",
    ),
    "southeast": RegionalPrice(
        region="Southeast US",
        price_per_yard=140.0,
        short_load_fee=60.0,
        short_load_threshold_yards=3.0,
        notes="AL, FL, GA, KY, MS, NC, SC, TN, VA, WV",
    ),
    "midwest": RegionalPrice(
        region="Midwest US",
        price_per_yard=145.0,
        short_load_fee=65.0,
        short_load_threshold_yards=3.0,
        notes="IA, IL, IN, KS, MI, MN, MO, NE, ND, OH, SD, WI",
    ),
    "southwest": RegionalPrice(
        region="Southwest US",
        price_per_yard=155.0,
        short_load_fee=70.0,
        short_load_threshold_yards=3.0,
        notes="AZ, NM, OK, TX",
    ),
    "west": RegionalPrice(
        region="West US",
        price_per_yard=170.0,
        short_load_fee=80.0,
        short_load_threshold_yards=3.0,
        notes="CA, CO, HI, ID, MT, NV, OR, UT, WA, WY, AK",
    ),
    "national": RegionalPrice(
        region="National Average",
        price_per_yard=150.0,
        short_load_fee=65.0,
        short_load_threshold_yards=3.0,
        notes="Weighted national average",
    ),
}


def get_regional_price(region: str = "national") -> RegionalPrice:
    """Look up approximate concrete pricing for a US region.

    Args:
        region: One of ``northeast``, ``southeast``, ``midwest``,
                ``southwest``, ``west``, or ``national``.

    Raises:
        ValueError: If the region key is not recognised.
    """
    key = region.lower().strip()
    result = _REGIONS.get(key)
    if result is None:
        valid = ", ".join(sorted(_REGIONS))
        raise ValueError(f"Unknown region '{region}'. Choose from: {valid}")
    return result


def list_regions() -> list[str]:
    """Return all available region keys."""
    return sorted(_REGIONS)
