package model;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Base class for file transformations and conversions.
 */
public class Transform {
    private Client client;
    private String source;
    private FileLink fileLink;

    ArrayList<Task> tasks;

    Transform(Client client, String source) {
        this.client = client;
        this.source = source;
        this.tasks = new ArrayList<>();
    }

    Transform(FileLink fileLink) {
        this.fileLink = fileLink;
        this.tasks = new ArrayList<>();
    }

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

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

        void addOption(String key, Object value) {
            addOption(key, value.toString());
        }

        void addOption(String key, Object value[]) {
            String valueString = Arrays.toString(value);
            // Remove spaces between array items
            valueString = valueString.replace(" ", "");
            addOption(key, valueString);
        }

        void addOption(String key, String value) {
            options.add(new Option(key, value));
        }

        @Override
        public String toString() {
            StringBuilder stringBuilder = new StringBuilder(name);
            stringBuilder.append("=");
            for (Option option : options)
                stringBuilder.append(option.key).append(":").append(option.value).append(",");
            return stringBuilder.toString();
        }
    }

    /**
     * Each {@link Task Task} object has options.
     * These are the settings for that task.
     * For example the resize task would have options for width and height.
     */
    protected static class Option {
        String key;
        String value;

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

@@ -9,16 +9,47 @@
 model;%0A%0A
+import util.FilestackService;%0A%0A
 import j
@@ -293,24 +293,78 @@
 sk%3E tasks;%0A%0A
+    private FilestackService.Process processService;%0A%0A
     Transfor
@@ -413,137 +413,241 @@
 this
-.
+(
 client
- = client
+, source, null)
 ;%0A    
+%7D%0A%0A
     
-this.source = source;%0A        this.tasks = new ArrayList%3C%3E();%0A    %7D%0A%0A    Transform(FileLink fileLink) %7B
+Transform(FileLink fileLink) %7B%0A        this(null, null, fileLink);%0A    %7D%0A%0A    Transform(Client client, String source, FileLink fileLink) %7B%0A        this.client = client;%0A        this.source = source;
 %0A   

Simplify constructors