<?php

namespace api\v2\objects\status;
use api\v2\Base;

use function api\v2\import_common;
import_common();

/**
 * API wrapper for get_xml_host_status, look into the function to learn more about the structure of the output
 */
class host extends Base {
    public function authorized_for_get() {
        return true;
    }

    public function get() {
        global $request;
        $response = get_xml_host_status($request);
        if(!$response || $response->recordcount == 0) {
            $response = array( "recordcount" => 0, "hoststatus" => [] );
        }

        // Ensure object is always an array
        $response = json_decode(json_encode($response), false);
        if (!isset($response->hoststatus)) {
            $response->hoststatus = [];
        } else if (!is_array($response->hoststatus)) {
            $response->hoststatus = [$response->hoststatus];
        }
        return $response;
    }
}