<?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 Radio extends Model {

    public $id;
    public $radio_mac;
    public $interface;
    public $remote_cap_name;
    public $remote_cap_name_identity;

    public function rules() {
        return [
            ['id', 'string'],
            ['radio_mac', 'string'],
            ['interface', 'string'],
            ['remote_cap_name', 'string'],
            ['remote_cap_name_identity', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/caps-man/radio/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->radio_mac = $response->getProperty('radio-mac');
                $c->interface = $response->getProperty('interface');
                $c->remote_cap_name = $response->getProperty('remote-cap-name');
                $c->remote_cap_name_identity = $response->getProperty('remote-cap-name-identity');
                $return[] = $c;
            }
        }
        return $return;
    }

}
