<?php

namespace ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Helpers;

use ThurData\Servers\KerioEmail\App\Enums\ProductParams;

/**
 *
 * Created by PhpStorm.
 * User: ThurData
 * Date: 18.09.19
 * Time: 09:22
 * Class AccountHelper
 */
class AccountHelper
{

    /**
     * @description return formatted data per API data
     * @param $date
     * @return false|string|null
     */
    public static function getFormattedData($date, $format = 'd/m/Y')
    {
        if(!$date)
        {
            return null;
        }
        $mydate = new \DateTime("@$date", new \DateTimeZone('UTC'));
        $localTZ = (new \DateTime)->getTimezone();
        $mydate->setTimezone($localTZ);
        return $mydate->format($format);
    }

    /**
     * @param $quote
     * @return float|int|string
     */
    public static function getQuotaAsMb($quote, $unit = 'Bytes')
    {
        switch($unit) {
            case 'Bytes' :
                $quote = $quote/1024/1024;
                break;
            case 'KiloBytes' :
                $quote = $quote/1024;
                break;
            case 'MegaBytes' :
                $quote = $quote;
                break;
            case 'GigaBytes' :
                $quote = $quote*1024;
                break;
        }

        return isset($quote) ? round($quote,2) : ProductParams::SIZE_UNLIMITED;
    }

}