package jnet.lib.object;

import java.io.Serializable;

public class Connection implements Serializable {

    public static final int TYPE_OTHER = 0;
    public static final int TYPE_GE = 1;
    public static final int TYPE_FE = 2;
    public static final int TYPE_E = 3;
    public static final int TYPE_10GE = 4;
    public static final int TYPE_100M_FIBER = 5;
    public static final int TYPE_1G_FIBER = 6;
    public static final int TYPE_10G_FIBER = 7;
    public static final int TYPE_WIRELESS = 8;
    public static final int TYPE_TUNEL = 9;
    public static final int TYPE_VLAN = 10;

    private int id;
    private int sourceObj;
    private int destinationObj;
    private int type;
    private int map;
    private boolean readTraffic;
    private int trafficObject;
    private int trafficIface;
    private long rx;
    private long tx;

    public Connection(int id, int sourceObj, int destinationObj, int type, int map, boolean readTraffic, int trafficObject, int trafficIface) {
        this.id = id;
        this.sourceObj = sourceObj;
        this.destinationObj = destinationObj;
        this.type = type;
        this.map = map;
        this.readTraffic = readTraffic;
        this.trafficObject = trafficObject;
        this.trafficIface = trafficIface;
        this.rx = 0;
        this.tx = 0;
    }

    public Connection(int sourceObj, int destinationObj, int type, int map, boolean readTraffic, int trafficObject, int trafficIface) {
        this.sourceObj = sourceObj;
        this.destinationObj = destinationObj;
        this.type = type;
        this.map = map;
        this.readTraffic = readTraffic;
        this.trafficObject = trafficObject;
        this.trafficIface = trafficIface;
        this.rx = 0;
        this.tx = 0;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getSourceObj() {
        return sourceObj;
    }

    public void setSourceObj(int sourceObj) {
        this.sourceObj = sourceObj;
    }

    public int getDestinationObj() {
        return destinationObj;
    }

    public void setDestinationObj(int destinationObj) {
        this.destinationObj = destinationObj;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getMap() {
        return map;
    }

    public void setMap(int map) {
        this.map = map;
    }

    public boolean isReadTraffic() {
        return readTraffic;
    }

    public void setReadTraffic(boolean readTraffic) {
        this.readTraffic = readTraffic;
    }

    public int getTrafficObject() {
        return trafficObject;
    }

    public void setTrafficObject(int trafficObject) {
        this.trafficObject = trafficObject;
    }

    public int getTrafficIface() {
        return trafficIface;
    }

    public void setTrafficIface(int trafficIface) {
        this.trafficIface = trafficIface;
    }

    public String getRx() {
        return convertBps(rx);
    }

    public void setRx(long rx) {
        this.rx = rx;
    }

    public String getTx() {
        return convertBps(tx);
    }

    public void setTx(long tx) {
        this.tx = tx;
    }

    public static String convertBps(long Bps) {
        double bitsPerSec = Bps * 8.0;  // Převod na bity za sekundu jako double pro přesnost
        if (bitsPerSec >= 1_000_000_000) {
            return String.format("%.2f Gbps", bitsPerSec / 1_000_000_000.0);
        } else if (bitsPerSec >= 1_000_000) {
            return String.format("%.2f Mbps", bitsPerSec / 1_000_000.0);
        } else if (bitsPerSec >= 1_000) {
            return String.format("%.2f Kbps", bitsPerSec / 1_000.0);
        } else {
            return String.format("%.0f bps", bitsPerSec);  // Zobrazení bez desetinných míst pro malé hodnoty
        }
    }

}
