<?php


namespace ModulesGarden\Servers\ProxmoxVps\App\Http\Client;


use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\CloneQemuJob;
use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\CreateLxcJob;
use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\CreateQemuJob;
use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\LoadBalancer\UpgradeVmJob;
use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\MigrateVmJob;
use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\Reinstall\CreateVmJob;
use ModulesGarden\ProxmoxAddon\App\Jobs\Vps\RestoreVm;
use ModulesGarden\ProxmoxAddon\App\Models\Job;
use ModulesGarden\Servers\ProxmoxVps\App\UI\Home\Pages\VpsBuild;
use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\view;


trait BaseClientController
{
    public function isVpsCreated()
    {
        $jobs = [
            CloneQemuJob::class,
            CreateQemuJob::class,
            CreateLxcJob::class,
            MigrateVmJob::class,
            RestoreVm::class,
            \ModulesGarden\ProxmoxAddon\App\Jobs\Vps\Reinstall\RestoreVm::class,
            UpgradeVmJob::class,
            CreateVmJob::class
        ];
        if(Job::waiting()->ofHostingId($this->getWhmcsParamByKey("serviceid"))->ofJobs($jobs)->count() > 0){
            return false;
        }else if (!$this->getWhmcsCustomField("vmid")){
            return false;
        }
        return true;
    }

    public function onVpsBuild()
    {
        return view()->addElement(VpsBuild::class);
    }
}