<?php

namespace App\Services;

class PriceCalculate
{

    static function calculate($day, $price, $total)
    {

        //     if(config('app.billing_day_count')==false){
        //       $d = $day;
        //     }else{
        //       $d = config('app.billing_day_count');
        //     }
        //     // dd($d);
        //     return round(($price/$d)*$total);
        // }


        // Validate and convert inputs to numeric values
        $day = is_numeric($day) ? (float)$day : 0;
        $price = is_numeric($price) ? (float)$price : 0;
        $total = is_numeric($total) ? (float)$total : 0;

        // Get billing day count with validation
        $billingDayCount = config('app.billing_day_count');

        if (config('app.billing_day_count') == false) {
            $d = $day;
        } else {
            $d = is_numeric($billingDayCount) ? (float)$billingDayCount : $day;
        }

        // Ensure we don't divide by zero
        if ($d <= 0) {
            return 0;
        }

        // dd($d);
        return round(($price / $d) * $total);
    }
}
