package org.batfish.common;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import org.batfish.common.BfConsts.TaskStatus;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;

public class Task {

   public static class Batch {

      private static final String COMPLETED_VAR = "completed";

      private static final String DESCRIPTION_VAR = "description";

      private static final String SIZE_VAR = "size";

      private AtomicInteger _completed;

      private String _description;

      private int _size;

      @JsonCreator
      private Batch() {
         _completed = new AtomicInteger();
      }

      @JsonProperty(COMPLETED_VAR)
      public AtomicInteger getCompleted() {
         return _completed;
      }

      @JsonProperty(DESCRIPTION_VAR)
      public String getDescription() {
         return _description;
      }

      @JsonProperty(SIZE_VAR)
      public int getSize() {
         return _size;
      }

      @JsonProperty(COMPLETED_VAR)
      private void setCompleted(AtomicInteger completed) {
         _completed = completed;
      }

      @JsonProperty(DESCRIPTION_VAR)
      public void setDescription(String description) {
         _description = description;
      }

      @JsonProperty(SIZE_VAR)
      public void setSize(int size) {
         _size = size;
      }

   }

   private static final String ARGS_VAR = "args";

   private static final String OBTAINED_VAR = "obtained";

   private static final String STATUS_VAR = "status";

   private static final String TERMINATED_VAR = "terminated";

   private String[] _args;

   private List<Batch> _batches;

   private Date _obtained;

   private TaskStatus _status;

   private Date _terminated;

   private volatile boolean _terminationRequested;

   @JsonCreator
   private Task() {
   }

   public Task(String[] args) {
      this._args = args;
      _batches = new ArrayList<>();
      _obtained = new Date();
      _terminated = null;
      _status = TaskStatus.Unscheduled;
   }

   @JsonProperty(ARGS_VAR)
   public String[] getArgs() {
      return _args;
   }

   public List<Batch> getBatches() {
      return _batches;
   }

   @JsonProperty(OBTAINED_VAR)
   public Date getObtained() {
      return _obtained;
   }

   @JsonProperty(STATUS_VAR)
   public TaskStatus getStatus() {
      return _status;
   }

   @JsonProperty(TERMINATED_VAR)
   public Date getTerminated() {
      return _terminated;
   }

   @JsonIgnore
   public boolean getTerminationRequested() {
      return _terminationRequested;
   }

   public Batch newBatch(String description) {
      Batch batch = new Batch();
      batch.setDescription(description);
      _batches.add(batch);
      return batch;
   }

   @JsonIgnore
   public void requestTermination() {
      _terminationRequested = true;
   }

   @JsonProperty(ARGS_VAR)
   public void setArgs(String[] args) {
      _args = args;
   }

   public void setBatches(List<Batch> batches) {
      _batches = batches;
   }

   @JsonProperty(OBTAINED_VAR)
   public void setObtained(Date obtained) {
      _obtained = obtained;
   }

   @JsonProperty(STATUS_VAR)
   public void setStatus(TaskStatus status) {
      _status = status;
   }

   public void setTerminated() {
      _terminated = new Date();
   }

   @JsonProperty(TERMINATED_VAR)
   public void setTerminated(Date terminated) {
      _terminated = terminated;
   }
}

@@ -590,24 +590,89 @@
  = %22size%22;%0A%0A
+      private static final String START_DATE_VAR = %22startDate%22;%0A%0A
       privat
@@ -695,24 +695,24 @@
 _completed;%0A
-
 %0A      priva
@@ -762,16 +762,48 @@
 _size;%0A%0A
+      private Date _startDate;%0A%0A
       @J
@@ -1203,32 +1203,140 @@
 _size;%0A      %7D%0A%0A
+      @JsonProperty(START_DATE_VAR)%0A      public Date getStartDate() %7B%0A         return _startDate;%0A      %7D%0A%0A
       @JsonPrope
@@ -1657,24 +1657,24 @@
 int size) %7B%0A
-
          _si
@@ -1693,16 +1693,143 @@
      %7D%0A%0A
+      @JsonProperty(START_DATE_VAR)%0A      public void setStartDate(Date startDate) %7B%0A         _startDate = startDate;%0A      %7D%0A%0A
    %7D%0A%0A  
@@ -3151,16 +3151,78 @@
 ption);%0A
+      Date date = new Date();%0A      batch.setStartDate(date);%0A
       _b

add start date to task progress