package com.hubspot.singularity;

import java.util.Map;

import com.google.common.base.Optional;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

public class SingularitySlaveUsage {

  public enum ResourceUsageType {
    CPU_USED, MEMORY_BYTES_USED
  }

  public static final long BYTES_PER_MEGABYTE = 1024L * 1024L;

  private final long memoryBytesUsed;
  private final long memoryMbReserved;
  private final int numTasks;
  private final long timestamp;
  private final double cpusUsed;
  private final double cpusReserved;
  private final Optional<Long> memoryMbTotal;
  private final Optional<Double> cpusTotal;
  private final Map<ResourceUsageType, Number> longRunningTasksUsage;

  @JsonCreator
  public SingularitySlaveUsage(@JsonProperty("memoryBytesUsed") long memoryBytesUsed,
                               @JsonProperty("memoryMbReserved") long memoryMbReserved,
                               @JsonProperty("timestamp") long timestamp,
                               @JsonProperty("cpusUsed") double cpusUsed,
                               @JsonProperty("cpusReserved") double cpusReserved,
                               @JsonProperty("numTasks") int numTasks,
                               @JsonProperty("memoryMbTotal") Optional<Long> memoryMbTotal,
                               @JsonProperty("cpusTotal") Optional<Double> cpusTotal,
                               @JsonProperty("longRunningTasksUsage") Map<ResourceUsageType, Number> longRunningTasksUsage) {
    this.memoryBytesUsed = memoryBytesUsed;
    this.memoryMbReserved = memoryMbReserved;
    this.timestamp = timestamp;
    this.cpusUsed = cpusUsed;
    this.cpusReserved = cpusReserved;
    this.numTasks = numTasks;
    this.memoryMbTotal = memoryMbTotal;
    this.cpusTotal = cpusTotal;
    this.longRunningTasksUsage = longRunningTasksUsage;
  }

  public long getMemoryBytesUsed() {
    return memoryBytesUsed;
  }

  public long getMemoryMbReserved() {
    return memoryMbReserved;
  }

  public long getTimestamp() {
    return timestamp;
  }

  public double getCpusUsed() {
    return cpusUsed;
  }

  public double getCpusReserved() {
    return cpusReserved;
  }

  public int getNumTasks() {
    return numTasks;
  }

  public Optional<Long> getMemoryBytesTotal() {
    return memoryMbTotal.isPresent() ? Optional.of(memoryMbTotal.get() * BYTES_PER_MEGABYTE) : Optional.absent();
  }

  public Optional<Long> getMemoryMbTotal() {
    return memoryMbTotal.isPresent() ? Optional.of(memoryMbTotal.get()) : Optional.absent();
  }

  public Optional<Double> getCpusTotal() {
    return cpusTotal;
  }

  public Map<ResourceUsageType, Number> getLongRunningTasksUsage() {
    return longRunningTasksUsage;
  }

  @Override
  public String toString() {
    return "SingularitySlaveUsage [memoryBytesUsed=" + memoryBytesUsed + ", memoryMbReserved=" + memoryMbReserved + ", memoryMbTotal=" + memoryMbTotal + ", cpusUsed=" + cpusUsed + ", cpusReserved=" + cpusReserved + ", cpusTotal=" + cpusTotal + ", numTasks=" + numTasks + ", timestamp=" + timestamp + "]";
  }
}

@@ -2864,24 +2864,32 @@
 yBytesUsed +
+%0A       
  %22, memoryMb
@@ -2915,24 +2915,32 @@
 MbReserved +
+%0A       
  %22, memoryMb
@@ -2960,24 +2960,32 @@
 oryMbTotal +
+%0A       
  %22, cpusUsed
@@ -2995,24 +2995,32 @@
 + cpusUsed +
+%0A       
  %22, cpusRese
@@ -3042,16 +3042,24 @@
 served +
+%0A       
  %22, cpus
@@ -3079,16 +3079,24 @@
 sTotal +
+%0A       
  %22, numT
@@ -3114,16 +3114,85 @@
 mTasks +
+%0A        %22, longRunningTasksUsage=%22 + longRunningTasksUsage +%0A       
  %22, time
@@ -3212,16 +3212,24 @@
 estamp +
+%0A       
  %22%5D%22;%0A  

add variable to toString