<?php

namespace app\models\mikrotik\routing\bfd;

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

    public $id;
    public $interface;
    public $address;
    public $protocols;
    public $state;

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

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/routing/bfd/neighbor/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Neighbor();
                $c->id = $response->getProperty('.id');
                $c->interface = $response->getProperty('interface');
                $c->address = $response->getProperty('address');
                $c->protocols = $response->getProperty('protocols');
                $c->state = $response->getProperty('state');
                $return[] = $c;
            }
        }
        return $return;
    }

}
