<?php

namespace app\models\mikrotik\system;

use yii\base\Model;
use Yii;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

use PEAR2\Net\RouterOS;
use app\models\mikrotik\MikrotikConnect;

class Routerboard extends Model {

    public $routerboard;
    public $model;
    public $serial_number;
    public $firmware_type;
    public $factory_firmware;
    public $current_firmware;
    public $upgrade_firmware;

    public function rules() {
        return [
            ['routerboard', 'string'],
            ['model', 'string'],
            ['serial_number', 'string'],
            ['firmware_type', 'string'],
            ['factory_firmware', 'string'],
            ['current_firmware', 'string'],
            ['upgrade_firmware', 'string'],
        ];
    }

    public function get() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/system/routerboard/print');

        $response = $connect->getConnection()->sendSync($getRequest);

        $this->routerboard = (($response->getProperty('routerboard') == 'true') ? true : false);
        $this->model = $response->getProperty('model');
        $this->serial_number = $response->getProperty('serial-number');
        $this->firmware_type = $response->getProperty('firmware-type');
        $this->factory_firmware = $response->getProperty('factory-firmware');
        $this->current_firmware = $response->getProperty('current-firmware');
        $this->upgrade_firmware = $response->getProperty('upgrade-firmware');

        return;
    }

}
