<?php

namespace app\models\mikrotik\routing\ospf;

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

    public $router_id;
    public $address;
    public $interface;
    public $state_changes;
    public $state;
    public $id;

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

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

}
