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

    public $instance;
    public $router_id;
    public $gateway;
    public $interface;
    public $cost;
    public $state;
    public $id;

    public function rules() {
        return [
            ['instance', 'string'],
            ['router_id', 'string'],
            ['gateway', 'string'],
            ['interface', 'string'],
            ['cost', 'string'],
            ['state', 'string'],
            ['id', 'string'],
        ];
    }

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

}
