"""
Cost estimation for concrete projects.

For up-to-date regional pricing, see
https://www.slabcalc.co/calculators/concrete-cost-calculator
"""

from __future__ import annotations

import math
from typing import TypedDict

from concrete_calc.bags import bag_estimate
from concrete_calc.units import cubic_yards_to_cubic_feet

__all__ = ["ready_mix_cost", "bag_cost", "ReadyMixResult", "BagCostResult"]


class ReadyMixResult(TypedDict):
    yards: float
    cost: float
    short_load: bool


class BagCostResult(TypedDict):
    bags: int
    cost: float


def ready_mix_cost(
    cubic_yards: float,
    price_per_yard: float = 150.0,
    short_load_fee: float = 0.0,
    short_load_threshold: float = 1.0,
) -> ReadyMixResult:
    """Estimate ready-mix truck cost.

    Args:
        cubic_yards: Volume to order.
        price_per_yard: Local price per cubic yard.
        short_load_fee: Extra fee if below minimum load.
        short_load_threshold: Yards below which the short-load fee applies.
    """
    short_load = cubic_yards < short_load_threshold
    raw = cubic_yards * price_per_yard + (short_load_fee if short_load else 0)
    return ReadyMixResult(
        yards=cubic_yards,
        cost=round(raw, 2),
        short_load=short_load,
    )


def bag_cost(
    cubic_feet: float,
    bag_size: int = 80,
    price_per_bag: float = 6.50,
) -> BagCostResult:
    """Estimate bagged-concrete cost.

    Args:
        cubic_feet: Total volume.
        bag_size: Bag weight in lbs (40, 50, 60, or 80).
        price_per_bag: Retail price per bag.
    """
    count = bag_estimate(cubic_feet, bag_size)
    return BagCostResult(bags=count, cost=round(count * price_per_bag, 2))
