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

    public $instance;
    public $area;
    public $type;
    public $id;
    public $originator;
    public $sequence_number;
    public $age;

    public function rules() {
        return [
            ['instance', 'string'],
            ['area', 'string'],
            ['type', 'string'],
            ['originator', 'string'],
            ['id', 'string'],
            ['sequence_number', 'string'],
            ['age', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/routing/ospf/lsa/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Lsa();
                $c->instance = $response->getProperty('instance');
                $c->area = $response->getProperty('area');
                $c->type = $response->getProperty('type');
                $c->id = $response->getProperty('id');
                $c->originator = $response->getProperty('originator');
                $c->sequence_number = $response->getProperty('sequence-number');
                $c->age = $response->getProperty('age');
                $return[] = $c;
            }
        }
        return $return;
    }

}
