<?php


namespace ModulesGarden\ProxmoxAddon\App\Services\Cloud;


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

class FirewallOptionService
{
    use WhmcsParams;
    use ApiService;
    use ProductService;

    public function update(){
        $attributes = [
            "enable" => $this->configuration()->isFirewalOptionEnable() ? 1 : 0,
            "dhcp" => $this->configuration()->isFirewalOptionDhcp()? 1 : 0,
            "ndp" => $this->configuration()->isFirewalOptionNdp()? 1 : 0,
            "radv" => $this->configuration()->isFirewalOptionRadv() ? 1 : 0,
            "macfilter" => $this->configuration()->isFirewalOptionMacfilter() ? 1 : 0,
            "ipfilter" => $this->configuration()->isFirewalOptionIpfilter() ? 1 : 0,
        ];
        if( $this->configuration()->firewalOptionPolicyIn){
            $attributes['policy_in'] = $this->configuration()->firewalOptionPolicyIn;
        }
        if( $this->configuration()->firewalOptionPolicyOut){
            $attributes['policy_out'] = $this->configuration()->firewalOptionPolicyOut;
        }
        sl('Vm')->getVm()->firewallOptions()->setAttributes($attributes)->update();
    }

}