"use strict";(function(){"use strict";var e=require("util");var t=require("events");function r(){t.EventEmitter.call(this);if(false===this instanceof r){return new r}this.state="unconnected"}e.inherits(r,t.EventEmitter);r.prototype.setUpSystem=function(e){var t=this;t.deviceInstance=e;var r=t.deviceInstance.isConnect();if(r===true){t.state="connected"}};r.prototype.getUpTime=function(e){var t=this;var r="show ver";var a=function i(t){var r=t.split(/\r?\n/gi);for(var a=0;a<r.length;a++){if(r[a].search("System uptime")!==-1){var i=r[a].split(": ")[1];e("",i);break}}};if(t.state=="connected"){t.deviceInstance.exec(r,a)}else{e("not connected yet")}};r.prototype.getVsuInfo=function(e){var t=this;var r="show switch virtual topology";var a=function i(r){var a=[];var i=[];var n=r.split(/\r?\n/gi);for(var s=0;s<n.length;s++){if(n[s].search("---")!==-1){var c=n[s].split("]");for(var o=1;o<c.length;o++){if(c[o].search("---")==-1){continue}var v=c[o].split("---");var p=v[0].split("(")[1].split(")")[0];var f=v[1].split("(")[1].split(")")[0];var l={upDevice:p,downDevice:f,linkStatus:"UP"};a.push(l)}}if(n[s].search("MAC:")!==-1){var v=n[s].split(",");var h=v[0].split("[")[1].split("]")[0];var u="STANDBY";if(n[s].search("ACTIVE")!==-1||n[s].search("master")!==-1){u="ACTIVE"}else if(n[s].search("CANDIDATE")!==-1||n[s].search("candidate")!==-1){u="CANDIDATE"}var d={device_id:h,role:u};i.push(d)}}var g=function m(t){var r=t.split(/\r?\n/gi);for(var n=0;n<a.length;n++){for(var s=0;s<r.length;s++){if(r[s].search(a[n].upDevice)!==-1&&r[s].search(a[n].nextDev)!==-1&&r[s].search("DOWN")!==-1){a[n].linkStatus="DOWN"}}}e("",i,a)};var _="show switch virtual link";t.deviceInstance.exec(_,g)};if(t.state=="connected"){t.deviceInstance.exec(r,a)}else{e("not connected yet")}};r.prototype.getBfdInfo=function(e){var t=this;var r="show switch virtual dual-active bfd";var a=function i(t){var r=true;var a=[];var i=t.split(/\r?\n/gi);var n=false;for(var s=0;s<i.length;s++){if(i[s].search("BFD dual-active detection enabled")!==-1&&i[s].search("No")!==-1){r=false;break}if(r==true){if(i[s].charAt(0)==" "){var c=i[s].split(":")[0].split("  ")[1];var o=i[s].split(":")[1];var v={port:c,status:o};a.push(v)}}}e("",a)};if(t.state=="connected"){t.deviceInstance.exec(r,a)}else{e("not connected yet")}};r.prototype.getVslInfo=function(e){var t=this;var r="show switch virtual link port";var a=function i(t){var r=t.split(/\r?\n/gi);var a="";var i=[];for(var n=0;n<r.length;n++){if(r[n].search("Ethernet")!==-1&&r[n].search("OK")!==-1){var s=0;var c=false;var o={pre_port:"",pre_status:"UP",next_port:"",next_status:"UP",uptime:""};var v=r[n].split("    ");for(var p=0;p<v.length;p++){var f=v[p].trim();if(f.search("Ethernet")!==-1&&a.search(f)==-1){a=a+" "+f;if(s==0){o.pre_port=f}else{o.next_port=f}s++;c=true}if(c==true&&f.search(",")!==-1){o.uptime=f}}if(c==true){i.push(o)}}}e("",i)};if(t.state=="connected"){t.deviceInstance.exec(r,a)}else{e("not connected yet")}};r.prototype.getUpDownPort=function(e){var t=this;var r="show ip interface brief";var a=function i(t){var r=false;var a=[];var i=t.split(/\r?\n/gi);for(var n=0;n<i.length;n++){if(i[n].search("Protocol")!==-1){r=true}if(r==false){continue}var s=false;var c={port_name:"",port_status:"up",ip_address:"",peer_ip_address:"--"};var o=i[n].split("    ");c.port_name=o[0];if(c.port_name.search("-")!==-1){continue}for(var v=1;v<o.length;v++){if(o[v].search("down")!==-1){c.port_status="down"}if(o[v].search("/")!==-1){c.ip_address=o[v].trim();s=true}}if(s==true){a.push(c)}}e("",a)};if(t.state=="connected"){t.deviceInstance.exec(r,a)}else{e("not connected yet")}};module.exports=r})();