<?php

namespace App\Modules\Network\Helpers;

use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Http;

define('POLICY_ADDRESS_GROUP', 'policy/address-group');
define('POLICY_PROTECTION_PROFILE', 'policy/protection-profile');
define('POLICY_DETECTION_PROFILE', 'policy/detection-profile');

class Corero {
   
    protected $endpoint, $username, $password, $version, $retries;
 
    function __construct(string $_endpoint, int $_version, string $_username, string $_password, int $_retries = 3) {
        $this->endpoint = $_endpoint;
        $this->username = $_username;
        $this->password = $_password;
        $this->version = $_version;
        $this->retries = $_retries;
    }

    public function get_request($_path, $_parameters = []) {
        return Http::withBasicAuth($this->username, $this->password)
            ->withOptions(['verify' => false])
            ->retry($this->retries, 100)
            ->get("$this->endpoint/api/v$this->version/$_path" , $_parameters, ['verify' => false]);
    }

    public function put_request($_path, $_parameters = []) {
        return Http::withBasicAuth($this->username, $this->password)
            ->withOptions(['verify' => false])
            ->retry($this->retries, 100)
            ->put("$this->endpoint/api/v$this->version/$_path" , $_parameters, ['verify' => false]);
    }

    public function get_address_group_list(string $_group) {
        return $this->get_request(POLICY_ADDRESS_GROUP . "/$_group/ip");
    }

    public function put_address_group_ip(string $_group, string $_ip) {
        //return $this->put_request(POLICY_ADDRESS_GROUP . "/$_group/ip/$_ip");
    }

    public function get_protection_profiles() {
        return $this->get_request(POLICY_PROTECTION_PROFILE);
    }

    public function get_detection_profiles() {
        return $this->get_request(POLICY_DETECTION_PROFILE);
    }

}

?>