<?php

namespace licenseplaterecognizer\helpers;

/**
 * @example raw response from license plate recognizer API
 * {
 *  "version": "1.54.0",
 *  "usage": {
 *      "calls": 98
 *  },
 * "license_key": "XXXXXXXXXX",
 * "webhooks": [],
 * "total_calls": 2500
 * }
 */
class licenseplaterecognizer_info
{
    public string $version;
    public object $usage; // e.g. {"calls": 98}
    public string $license_key;
    public array $webhooks;
    public int $total_calls;

    public function __construct(mixed $data)
    {
        $values = is_array($data) ? $data : (is_object($data) ? get_object_vars($data) : []);
        $usage = $values['usage'] ?? (object)['calls' => 0];
        if (is_array($usage)) {
            $usage = (object)$usage;
        } elseif (!is_object($usage)) {
            $usage = (object)['calls' => 0];
        }
        $usage->calls = is_numeric($usage->calls ?? null) ? (int)$usage->calls : 0;

        $this->version = (string)($values['version'] ?? '');
        $this->usage = $usage;
        $this->license_key = (string)($values['license_key'] ?? '');
        $this->webhooks = is_array($values['webhooks'] ?? null) ? $values['webhooks'] : [];
        $this->total_calls = is_numeric($values['total_calls'] ?? null) ? (int)$values['total_calls'] : 0;
    }
}
