<?php

namespace App\Modules\Payroll\Services;

/**
 * Derives overtime pay amount from minutes and monthly base salary.
 */
class PayrollOvertimeAmountCalculator
{
    public function amountFromMinutes(float $monthlySalary, int $overtimeMinutes): string
    {
        if ($overtimeMinutes <= 0 || $monthlySalary <= 0) {
            return '0.00';
        }

        $days = max(1.0, (float) config('payroll.overtime_days_per_month', 30));
        $hours = max(1.0, (float) config('payroll.overtime_hours_per_day', 8));
        $multiplier = max(0.0, (float) config('payroll.overtime_rate_multiplier', 1.5));
        $hourly = $monthlySalary / ($days * $hours);
        $pay = ($overtimeMinutes / 60) * $hourly * $multiplier;

        return number_format(round($pay, 2), 2, '.', '');
    }
}
