<?php

namespace app\models\mikrotik\mesh;

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

    public $mesh;
    public $type;
    public $mac_address;
    public $on_interface;
    public $lifetime;
    public $age;

    public function rules() {
        return [
            ['mesh', 'string'],
            ['type', 'string'],
            ['mac_address', 'string'],
            ['on_interface', 'string'],
            ['lifetime', 'string'],
            ['age', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/interface/mesh/fdb/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Fdb();
                $c->mesh = $response->getProperty('mesh');
                $c->type = $response->getProperty('type');
                $c->mac_address = $response->getProperty('mac-address');
                $c->on_interface = $response->getProperty('on-interface');
                $c->lifetime = $response->getProperty('lifetime');
                $c->age = $response->getProperty('age');
                $return[] = $c;
            }
        }
        return $return;
    }

}
