<?php


namespace ModulesGarden\ProxmoxAddon\App\Services\Vps;

use ModulesGarden\ProxmoxAddon\Core\UI\Traits\WhmcsParams;
use function ModulesGarden\ProxmoxAddon\Core\Helper\sl;

class AclService
{
    use ProductService;
    use WhmcsParams;

    public function backup()
    {
        if (!$this->configuration()->isPermissionBackup() && !$this->configuration()->isPermissionBackupJob())
        {
            throw new \Exception(sl("lang")->tr("No access to backup"));
        }
    }

    public function backupJob()
    {
        if (!$this->configuration()->isPermissionBackupJob())
        {
            throw new \Exception(sl("lang")->tr("No access to backup job"));
        }
    }

    public function novnc()
    {
        if (!$this->configuration()->isPermissionNovnc())
        {
            throw new \Exception(sl("lang")->tr("No access to noVNC console"));
        }
    }

    public function xtermjs()
    {
        if (!$this->configuration()->isPermissionXtermjs())
        {
            throw new \Exception(sl("lang")->tr("No access to Xterm.js console"));
        }
    }

    public function spice()
    {
        if (!$this->configuration()->isPermissionSpice())
        {
            throw new \Exception(sl("lang")->tr("No access to spice console"));
        }
    }

    public function disk()
    {
        if (!$this->configuration()->isPermissionDisk())
        {
            throw new \Exception(sl("lang")->tr("No access to disk"));
        }
    }

    public function firewall()
    {
        if (!$this->configuration()->isPermissionFirewall())
        {
            throw new \Exception(sl("lang")->tr("No access to firewall"));
        }
    }

    public function firewallOption()
    {
        if (!$this->configuration()->isPermissionFirewallOption())
        {
            throw new \Exception(sl("lang")->tr("No access to firewall option"));
        }
    }

    public function graph()
    {
        if (!$this->configuration()->isPermissionGraph())
        {
            throw new \Exception(sl("lang")->tr("No access to graph"));
        }
    }

    public function network()
    {
        if (!$this->configuration()->isPermissionNetwork())
        {
            throw new \Exception(sl("lang")->tr("No access to network"));
        }
    }

    public function reinstall()
    {
        if (!$this->configuration()->isPermissionReinstall())
        {
            throw new \Exception(sl("lang")->tr("No access to reinstall"));
        }
    }

    public function snapshot()
    {
        if (!$this->configuration()->isPermissionSnapshot())
        {
            throw new \Exception(sl("lang")->tr("No access to snapshot"));
        }
    }

    public function taskHistory()
    {
        if (!$this->configuration()->isPermissionTaskHistory())
        {
            throw new \Exception(sl("lang")->tr("No access to task history"));
        }
    }

    public function additionalDiskBackup()
    {
        if (!$this->configuration()->isPermissionAdditionalDiskBackup())
        {
            throw new \Exception(sl("lang")->tr("No access to additional disk backup"));
        }
    }

    public function hasFirewallOption($option)
    {
        return in_array( $option, $this->configuration()->getPermissionFirewalOptions());
    }
}