package io.thegrid.imgflourl;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Specification for the graph to be used for processing an image
 */
public abstract class Graph {
  public static final Integer NO_DIMENSION = null;

  /**
   * Graph that does nothing at all.
   */
  public static class NoOp extends Graph {
    public NoOp() {
      super("noop");
    }
  }

  /**
   * Simple graph that does nothing but resizing.
   */
  public static class Passthrough extends Graph {
    /**
     * Creates a new Passthrough graph configuration
     *
     * @param width  Target width of the image or {@link #NO_DIMENSION} for keeping the aspect ratio
     * @param height Target height of the image or {@link #NO_DIMENSION} for keeping the aspect ratio
     */
    public Passthrough(Integer width, Integer height) {
      super("passthrough");

      if (height != null) {
        addParam("height", height);
      }
      if (width != null) {
        addParam("width", width);
      }
    }
  }

  private final String name;
  private final Map<String, String> params;

  private Graph(String name) {
    this.name = name;
    this.params = new LinkedHashMap<String, String>();
  }

  public String getName() {
    return name;
  }

  public Map<String, String> getParams() {
    return params;
  }

  void addParam(String name, String value) {
    params.put(name, value);
  }

  void addParam(String name, int value) {
    addParam(name, String.valueOf(value));
  }
}

@@ -379,16 +379,328 @@
  %7D%0A  %7D%0A%0A
+  private static abstract class WidthHeightGraph extends Graph %7B%0A    private WidthHeightGraph(String name, Integer width, Integer height) %7B%0A      super(name);%0A%0A      if (height != null) %7B%0A        addParam(%22height%22, height);%0A      %7D%0A      if (width != null) %7B%0A        addParam(%22width%22, width);%0A      %7D%0A    %7D%0A  %7D%0A%0A
   /**%0A  
@@ -787,32 +787,43 @@
 through extends 
+WidthHeight
 Graph %7B%0A    /**%0A
@@ -1178,48 +1178,351 @@
 ugh%22
-);%0A%0A      if (height != null) %7B%0A    
+, width, height);%0A    %7D%0A  %7D%0A%0A  public static class GradientMap extends WidthHeightGraph %7B%0A    public GradientMap(Integer width, Integer height,%0A                       double stop1, double stop2, double stop3,%0A                       String color1, String color2, String color3, boolean srgb) %7B%0A      super(%22gradientmap%22, width, height);%0A%0A
     
+  
 addP
@@ -1531,102 +1531,240 @@
 am(%22
-height%22, height);%0A      %7D%0A      if (width != null) %7B%0A        addParam(%22width%22, width
+stop1%22, stop1);%0A      addParam(%22stop2%22, stop2);%0A      addParam(%22stop3%22, stop3);%0A%0A      addParam(%22color1%22, color1);%0A      addParam(%22color2%22, color2);%0A      addParam(%22color3%22, color3
 );%0A
+%0A
       
-%7D
+addParam(%22srgb%22, srgb ? %22True%22 : %22False%22);
 %0A   
@@ -2242,11 +2242,104 @@
 e));%0A  %7D
+%0A%0A  void addParam(String name, double value) %7B%0A    addParam(name, String.valueOf(value));%0A  %7D
 %0A%7D%0A

Add Gradient Map Graph