<?php

namespace app\models\mikrotik\ip\neighbors;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

use yii\base\Model;
use Yii;
use PEAR2\Net\RouterOS;
use app\models\mikrotik\MikrotikConnect;

class Neighbors extends Model {

    public $id;
    public $interface;
    public $address;
    public $address4;
    public $mac_address;
    public $identity;
    public $platform;
    public $version;
    public $board;
    public $ipv6;
    public $uptime;
    public $software_id;
    public $interface_name;

    public function rules() {
        return [
            ['id', 'string'],
            ['interface', 'string'],
            ['address', 'string'],
            ['address4', 'string'],
            ['mac_address', 'string'],
            ['identity', 'string'],
            ['platform', 'string'],
            ['version', 'string'],
            ['board', 'string'],
            ['ipv6', 'string'],
            ['uptime', 'string'],
            ['software_id', 'string'],
            ['interface_name', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/ip/neighbor/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Neighbors();
                $c->id = $response->getProperty('.id');
                $c->interface = $response->getProperty('interface');
                $c->address = $response->getProperty('address');
                $c->address4 = $response->getProperty('address4');
                $c->mac_address = $response->getProperty('mac-address');
                $c->identity = $response->getProperty('identity');
                $c->platform = $response->getProperty('platform');
                $c->version = $response->getProperty('version');
                $c->board = $response->getProperty('board');
                $c->ipv6 = $response->getProperty('ipv6');
                $c->uptime = $response->getProperty('uptime');
                $c->software_id = $response->getProperty('software-id');
                $c->interface_name = $response->getProperty('interface-name');
                $return[] = $c;
            }
        }
        return $return;
    }

}
