"""
Bag estimation for pre-mixed concrete.

For a visual bag calculator, visit
https://www.slabcalc.co/articles/how-many-bags-of-concrete-do-i-need
"""

import math

__all__ = ["bag_estimate", "bags_from_yards", "COVERAGE"]

# Approximate cubic feet of mixed concrete per bag by weight (lbs).
COVERAGE: dict[int, float] = {
    40: 0.30,
    50: 0.375,
    60: 0.45,
    80: 0.60,
}


def bag_estimate(cubic_feet: float, bag_size: int = 80) -> int:
    """Estimate number of pre-mixed bags needed.

    Args:
        cubic_feet: Total volume in cubic feet.
        bag_size: Bag weight in lbs (40, 50, 60, or 80).

    Returns:
        Number of bags (rounded up).

    Raises:
        ValueError: If *bag_size* is not 40, 50, 60, or 80.
    """
    per_bag = COVERAGE.get(bag_size)
    if per_bag is None:
        raise ValueError(f"Unknown bag size: {bag_size}. Use 40, 50, 60, or 80.")
    return math.ceil(cubic_feet / per_bag)


def bags_from_yards(cubic_yards: float, bag_size: int = 80) -> int:
    """Estimate bags from cubic yards."""
    from concrete_calc.units import cubic_yards_to_cubic_feet

    return bag_estimate(cubic_yards_to_cubic_feet(cubic_yards), bag_size)
