package com.filestack.model.transform.base;

import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * Generic task object.
 * A "task" in this case is a transformation, for example resize, crop, convert, etc.
 */
public class TransformTask {
    private String name;
    private ArrayList<Option> options;

    TransformTask() {
    }

    TransformTask(String name) {
        this.name = name;
        this.options = new ArrayList<>();
    }

    /**
     * These represent task parameters.
     * For example the resize task would have options for width and height.
     */
    private class Option {
        String key;
        String value;

        Option(String key, String value) {
            this.key = key;
            this.value = value;
        }
    }

    public void addOption(String key, Object value) {
        // Passing an empty key is a mistake, shouldn't happen
        if (key == null || key.length() == 0)
            throw new InvalidParameterException("Task option key cannot be empty");
        // Allowing the passing of a null value however, is for convenience
        // If we're leaving out an option for a transform task, we only need to check for that here
        if (value == null)
            return;

        String valueString;

        if (value.getClass().isArray())
            valueString = Arrays.toString((Object[])value);
        else
            valueString = value.toString();

        // Remove spaces between array items
        valueString = valueString.replace(" ", "");
        options.add(new Option(key, valueString));
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder(name);
        stringBuilder.append("=");
        for (Option option : options)
            if (option.value != null)
                stringBuilder.append(option.key).append(":").append(option.value).append(",");
        stringBuilder.deleteCharAt(stringBuilder.length()-1);
        return stringBuilder.toString();
    }
}

@@ -807,24 +807,77 @@
    %7D%0A    %7D%0A%0A
+    /** Add a key-value option pair to this task. */%0A
     public v
@@ -910,32 +910,32 @@
 Object value) %7B%0A
-
         // Passi
@@ -1026,16 +1026,18 @@
 () == 0)
+ %7B
 %0A       
@@ -1109,24 +1109,34 @@
 be empty%22);%0A
+        %7D%0A
         // A
@@ -1321,24 +1321,26 @@
 lue == null)
+ %7B
 %0A           
@@ -1347,16 +1347,26 @@
  return;
+%0A        %7D
 %0A%0A      
@@ -1427,16 +1427,18 @@
 Array())
+ %7B
 %0A       
@@ -1482,16 +1482,17 @@
 bject%5B%5D)
+ 
 value);%0A
@@ -1502,13 +1502,17 @@
     
+ %7D
  else
+ %7B
 %0A   
@@ -1551,16 +1551,26 @@
 tring();
+%0A        %7D
 %0A%0A      
@@ -1898,16 +1898,18 @@
 options)
+ %7B
 %0A       
@@ -1938,16 +1938,18 @@
 != null)
+ %7B
 %0A       
@@ -2032,24 +2032,48 @@
 ppend(%22,%22);%0A
+            %7D%0A        %7D%0A
         stri
@@ -2117,17 +2117,19 @@
 length()
--
+ - 
 1);%0A    

Fix linter warnings for TransfromTask