<?php

class virtua {
    private $apiKey = 'ec98cff4-mfkc-5995-zsot-1a2cb9534938';
    
    public function list_server() {
        $url = "https://api.virtua.cloud/cloud-server";
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            "Authorization: Basic $this->apiKey"
        ));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        return curl_exec($ch);
        curl_close($ch);
    }
    public function start($uuid) {
        $url = "https://api.virtua.cloud/cloud-server/$uuid/start";

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            "Authorization: Basic $this->apiKey"
        ));
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        return curl_exec($ch);
        curl_close($ch);
    }
    public function stop($uuid) {
        $url = "https://api.virtua.cloud/cloud-server/$uuid/stop";

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            "Authorization: Basic $this->apiKey"
        ));
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        return curl_exec($ch);
        curl_close($ch);
    }
    public function delet($uuid){
        $ch = curl_init();

        $url = "https://api.virtua.cloud/cloud-server/$uuid";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            "Authorization: Basic $this->apiKey"
        ));
        return curl_exec($ch);
        curl_close($ch);
    }
    public function create($zone , $system , $size , $name){
        $ch = curl_init();

        $url = 'https://api.virtua.cloud/cloud/order';
        $data = array(
            'zone' => $zone,
            'system' => $system,
            'offer' => $size,
            'project' => 'd467449d-fb1b-44b9-b861-d03f46c14c65',
            'cpu_family' => 'intel-xeon',
            'ipv6_enabled' => 1,
            'hostname' => $name
        );
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "Authorization: Basic $this->apiKey",
            'Content-Type: application/x-www-form-urlencoded; charset=UTF-8'
        ));
        return curl_exec($ch);
        curl_close($ch);
    }
    public function password($uuid){
        $ch = curl_init();

        $url = "https://api.virtua.cloud/cloud-server/$uuid/password?password=root";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            "Authorization: Basic $this->apiKey"
        ));
        return curl_exec($ch);
        curl_close($ch);
    }
}


?>
