<?php

namespace ModulesGarden\Servers\ProxmoxVps\App\UI\Resources\Providers;

use ModulesGarden\ProxmoxAddon\App\Libs\Format;
use ModulesGarden\ProxmoxAddon\App\Services\Vps\ResourceManager;

use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;

class BackupResourceProvider
{

    public function read()
    {
        $resourceManager = new ResourceManager();
        $lang = sl('lang');
        $bs = $resourceManager->backupSize();
        $resurces = [];
        if(!$bs->isUnlimited() ){
            $resurces[  ] = [
                "name" => $lang->tr($bs->getName()),
                "used" => Format::convertBytes($bs->getUsed()),
                "total" => $bs->isUnlimited() ? $lang->abtr("Unlimited") : Format::convertBytes($bs->getTotal()),
                "unit" => "",
                "percent" => $bs->getPercent()
            ];
        }
        if(!$resourceManager->backupFiles()->isUnlimited()){
            $resurces[ ] = [
                "name" => $lang->tr($resourceManager->backupFiles()->getName() ),
                "used" => $resourceManager->backupFiles()->getUsed(),
                "total" => $resourceManager->backupFiles()->getTotal(),
                "unit" => "",
                "percent" => $resourceManager->backupFiles()->getPercent()
            ];
        }
        return $resurces;
    }
}