<?php

namespace App\Modules\Payroll\Services;

/**
 * Unpaid leave deduction from monthly base salary (same day-count basis as OT).
 */
class PayrollLeaveDeductionCalculator
{
    public function amountFromDays(float $monthlySalary, float $unpaidLeaveDays): string
    {
        if ($unpaidLeaveDays <= 0 || $monthlySalary <= 0) {
            return '0.00';
        }

        $days = max(1.0, (float) config('payroll.overtime_days_per_month', 30));
        $daily = $monthlySalary / $days;
        $amount = $unpaidLeaveDays * $daily;

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