package vut.msa.pojos;

import org.hyperic.sigar.SigarException;
import vut.msa.monitor.system.SystemInformation;
import vut.msa.utilities.StringUtilities;

public class ClientInformation implements java.io.Serializable
{

    private short id;
    private Integer version;
    private long uptime;
    private long memoryRAM;
    private long memoryUsedPerc;
    private long diskUsed;
    private long diskTotal;
    private int documentsCount;
    private long documentsSize;

    private Client client;

    public ClientInformation() {
        this.uptime = 0;
        this.memoryRAM = 0;
        this.memoryUsedPerc = 0;
        this.diskUsed = 0;
        this.diskTotal = 0;
        this.documentsCount = 0;
        this.documentsSize = 0;
        this.version = 1;
    }

    public ClientInformation(Client client)  {
        this.uptime = 0;
        this.memoryRAM = 0;
        this.memoryUsedPerc = 0;
        this.diskUsed = 0;
        this.diskTotal = 0;
        this.documentsCount = 0;
        this.documentsSize = 0;
        this.client = client;
        this.version = 1;
    }

    public ClientInformation(long uptime, long memoryRAM, long memoryUsedPerc,
                             long diskUsed, long diskTotal, int documentsCount,
                             long documentsSize, Client client)
    {
        this.uptime = uptime;
        this.memoryRAM = memoryRAM;
        this.memoryUsedPerc = memoryUsedPerc;
        this.diskUsed = diskUsed;
        this.diskTotal = diskTotal;
        this.documentsCount = documentsCount;
        this.documentsSize = documentsSize;
        this.client = client;
        this.version = 1;
    }

    public ClientInformation (SystemInformation info, Client client) throws SigarException {

        this.uptime = (long) info.getUptime();
        this.memoryRAM = info.getMemoryRAM();
        this.memoryUsedPerc = (long) info.getMemoryUsedPerc();
        this.diskUsed = info.getUsedDisk();
        this.diskTotal = info.getTotalDisk();

        this.documentsCount = info.getDocumentsCount();
        this.documentsSize = info.getDocumentsSize();

        this.client = client;
        this.version = 1;
    }

    public short getId() { return id; }
    public void setId(short id) { this.id = id;}

    public Client getClient() { return client; }
    public void setClient(Client client) { this.client = client; }

    public long getDiskTotal() { return diskTotal; }
    public String getDiskTotalGB() { return diskTotal/(1024*1024) + " GB"; }
    public void setDiskTotal(long diskTotal) { this.diskTotal = diskTotal; }

    public long getDiskUsed() { return diskUsed; }
    public String getDiskUsedGB() { return diskUsed/(1024*1024) + " GB"; }
    public void setDiskUsed(long diskUsed) { this.diskUsed = diskUsed; }

    public int getDocumentsCount() { return documentsCount; }
    public void setDocumentsCount(int documentsCount) { this.documentsCount = documentsCount; }

    public long getDocumentsSize() { return documentsSize; }
    public String getDocumentsSizeString() {
        long inMB = documentsSize/(1024*1024);
        if (inMB > 1000) {
            return inMB/1024 + " GB";
        } else {
            return inMB + " MB";
        }
    }
    public void setDocumentsSize(long documentsSize) { this.documentsSize = documentsSize; }

    public long getMemoryRAM() { return memoryRAM; }
    public void setMemoryRAM(long memoryRAM) { this.memoryRAM = memoryRAM; }

    public long getMemoryUsedPerc() { return memoryUsedPerc; }
    public void setMemoryUsedPerc(long memoryUsedPerc) { this.memoryUsedPerc = memoryUsedPerc; }

    public long getUptime() { return uptime; }
    public String getFormatedUptime() { return StringUtilities.getFormatedUptime((int)uptime); }
    public void setUptime(long uptime) { this.uptime = uptime; }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ClientInformation other = (ClientInformation) obj;
        if (this.client != other.client && (this.client == null || !this.client.equals(other.client))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + (this.client != null ? this.client.hashCode() : 0);
        return hash;
    }

    
}
