<?php

namespace app\models\mikrotik\capsman;

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 Remote extends Model {

    public $id;
    public $address;
    public $name;
    public $state;
    public $radios;

    public function rules() {
        return [
            ['id', 'string'],
            ['address', 'string'],
            ['name', 'string'],
            ['state', 'string'],
            ['radios', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/caps-man/remote-cap/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Remote();
                $c->id = $response->getProperty('id');
                $c->address = $response->getProperty('address');
                $c->name = $response->getProperty('name');
                $c->state = $response->getProperty('state');
                $c->radios = $response->getProperty('radios');
                $return[] = $c;
            }
        }
        return $return;
    }

}
