<?php

if (!function_exists('hikvision_is_json')) {
    function hikvision_is_json($string)
    {
        if (!is_string($string) || trim($string) === '') {
            return false;
        }

        json_decode($string, true);
        return json_last_error() === JSON_ERROR_NONE;
    }
}

if (!function_exists('hikvision_parse_response')) {
    function hikvision_parse_response($body)
    {
        if (hikvision_is_json($body)) {
            return [
                'type' => 'json',
                'data' => json_decode($body, true),
                'raw'  => $body,
            ];
        }

        return [
            'type' => 'text',
            'data' => $body,
            'raw'  => $body,
        ];
    }
}

if (!function_exists('hikvision_now')) {
    function hikvision_now()
    {
        return date('Y-m-d H:i:s');
    }
}