<?php

    if ( ! defined( 'ABSPATH' ) ) exit;

    require_once __DIR__ . "/../../../Kernel/API/Entity/DigitalSignage4_ForfaitEntity.php";
    require_once "DigitalSignage4_Manager.php";
	
    class DigitalSignage4_UpdateManager extends DigitalSignage4_Manager
    {
        private static $managerEntityName = "Update";

        public static function get($currentVersion)
        {
            return self::getLastVersionUpdate($currentVersion);
        }

        private static function getLastVersionUpdate($currentversion)
        {
            $datas = self::getData($currentversion);
            if ($datas && !empty($datas)) {
                return end($datas);
            }
            return false;
        }

        private static function getData($currentVersion)
        {
            $demande = DigitalSignage4_API_Linker::get(self::$managerEntityName . "?version=" . $currentVersion, DigitalSignage4_ForfaitManager::instance()->getToken());

            if ($demande->getResponseCode() == 200) {
                return $demande->getDatas();
            }

            return false;
        }
    }
