<?php

namespace Modules\Vrc\Services\Technician;

/**
 * Pure productivity/commission math for a technician (spec §6.8). Kept free of
 * the framework so it is unit-testable: efficiency = billed ÷ actual hours,
 * commission = billed revenue × commission %.
 */
class ProductivityCalculator
{
    /**
     * @return array{billed_hours:float,actual_hours:float,efficiency:?float,billed_revenue:float,commission:float}
     */
    public static function compute(float $billedHours, float $actualMinutes, float $billedRevenue, ?float $commissionPct): array
    {
        $actualHours = round($actualMinutes / 60, 2);
        $efficiency = $actualHours > 0 ? round($billedHours / $actualHours, 2) : null;
        $commission = $commissionPct !== null ? round($billedRevenue * $commissionPct / 100, 2) : 0.0;

        return [
            'billed_hours'   => round($billedHours, 2),
            'actual_hours'   => $actualHours,
            'efficiency'     => $efficiency,
            'billed_revenue' => round($billedRevenue, 2),
            'commission'     => $commission,
        ];
    }
}
