<?php

namespace ModulesGarden\HostingQuotaNotifications\App\Helper\Basics;

use \ModulesGarden\HostingQuotaNotifications\App\Libs\Groups\Constants as Units;


/**
 * Description of Unit
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class Unit
{
    CONST MB_VALUE = 1;
    CONST GB_VALUE = 1024;
    CONST TB_VALUE = 1048576;
    
    public static function calculateByUnit($unit, $value, $limit = false)
    {
        switch($unit)
        {
            case Units::MB:
                return $value * self::MB_VALUE;
            case Units::GB:
                return $value * self::GB_VALUE;
            case Units::TB:
                return $value * self::TB_VALUE;
            case Units::PERCENTAGE:
                return $limit == false ? $value : self::calculatePercentages($value, $limit);
        }
        return $value;
    }

    public static function calculatePercentages($percent, $limit)
    {
        return $percent / 100 * $limit;
    }
}

