<?php

namespace App\Classes\Modules\Transactions\Services;

use App\Models\SegmentConstant;

class CalculatesTransactionTransferFee
{

    /**
     * @param float $amount
     * @param SegmentConstant|null $service_charge
     * @return float
     */
    public function execute(float $amount,  ?SegmentConstant $service_charge) {

        if(!$service_charge) {
            return 0;
        }

       return $service_charge->detail->transferFee->type === 'percentage' ? $amount * ((float) $service_charge->detail->transferFee->value /100) :  (float) $service_charge->detail->transferFee->value;
    }

}