<?php

namespace App\Support;

/**
 * Cobro por kg: mínimo 3 kg; fracción (0, 0.5] → +0.5; fracción > 0.5 → entero superior.
 */
final class LaundryWeightRounding
{
    public const MIN_KG = 3.0;

    public static function round(float $rawKg): float
    {
        $w = max(self::MIN_KG, $rawKg);
        $intPart = (int) floor($w);
        $frac = round($w - $intPart, 4);

        if ($frac <= 0.00001) {
            return (float) $intPart;
        }

        if ($frac <= 0.5) {
            return $intPart + 0.5;
        }

        return (float) ($intPart + 1);
    }
}
