<?php
namespace BooklyDepositPayments\Lib\Utils;

use Bookly\Lib\Utils\Price;

/**
 * Class Common
 * @package BooklyDepositPayments\Lib\Utils
 */
abstract class Common
{
    /**
     * Calculate deposit.
     *
     * @param double $deposit_amount
     * @param string $deposit
     * @param int    $number_of_persons
     * @return double
     */
    public static function calcDeposit( $deposit_amount, $deposit, $number_of_persons )
    {
        if ( strpos( $deposit, '%' ) === false ) {
            $deposit *= $number_of_persons;
        } else {
            $deposit = $deposit_amount * rtrim( $deposit, '%' ) / 100;
        }

        return round( min( $deposit, $deposit_amount ), 2 );
    }

    /**
     * Format deposit.
     *
     * @param double $deposit_amount
     * @param string $deposit
     * @return string
     */
    public static function formatDeposit( $deposit_amount, $deposit )
    {
        $result = Price::format( $deposit_amount );
        if ( strpos( $deposit, '%' ) !== false ) {
            $result .= ' (' . $deposit . ')';
        }

        return $result;
    }

}