package com.filestack.model.transform.base;

import com.filestack.model.FilestackClient;
import com.google.gson.JsonObject;
import com.filestack.model.FileLink;
import com.filestack.model.transform.tasks.StoreOptions;
import com.filestack.util.FilestackService;

import java.io.IOException;

/**
 * {@link Transform Transform} subclass for image transformations.
 */
public class ImageTransform extends Transform {

    public ImageTransform(FilestackClient fsClient, String source) {
        super(fsClient, source);
    }

    public ImageTransform(FileLink fileLink) {
        super(fileLink);
    }

    public JsonObject debug() throws IOException {
        String tasksString = getTasksString();

        if (apiKey != null)
            return processService.debugExternal(apiKey, tasksString, source).execute().body();
        else
            return processService.debug(tasksString, source).execute().body();
    }

    public FileLink store() throws IOException {
        return store(null);
    }

    public FileLink store(StoreOptions storeOptions) throws IOException {
        if (storeOptions == null)
            storeOptions = new StoreOptions();
        addTask(storeOptions);

        FilestackService.Process.StoreResponse response;
        String tasksString = getTasksString();

        if (apiKey != null)
            response = processService.storeExternal(apiKey, tasksString, source).execute().body();
        else
            response = processService.store(tasksString, source).execute().body();

        String handle = response.getUrl().split("/")[3];
        return new FileLink(apiKey, handle, security);
    }

    public ImageTransform addTask(ImageTransformTask task) {
        if (task == null)
            throw new IllegalArgumentException("Cannot add null task to image transform");
        tasks.add(task);
        return this;
    }
}

@@ -73,54 +73,12 @@
 File
-stackClient;%0Aimport com.google.gson.JsonObject
+Link
 ;%0Aim
@@ -98,36 +98,43 @@
 stack.model.File
-Link
+stackClient
 ;%0Aimport com.fil
@@ -220,16 +220,50 @@
 ervice;%0A
+import com.google.gson.JsonObject;
 %0Aimport 
@@ -588,32 +588,307 @@
 leLink);%0A    %7D%0A%0A
+    /**%0A     * Debugs the transformation as built so far, returning explanations of any issues.%0A     *%0A     * @return %7B@link JsonObject JSON%7D report for transformation%0A     * @throws IOException if a network error occurs, handle doesn't exist, or security is invalid%0A     */%0A
     public JsonO
@@ -989,32 +989,34 @@
 (apiKey != null)
+ %7B
 %0A            ret
@@ -1094,37 +1094,41 @@
 .body();%0A       
+ %7D
  else
+ %7B
 %0A            ret
@@ -1187,24 +1187,34 @@
 e().body();%0A
+        %7D%0A
     %7D%0A%0A    p
@@ -1284,32 +1284,419 @@
 e(null);%0A    %7D%0A%0A
+    /**%0A     * Stores the result of a transformation into a new file.%0A     * https://www.filestack.com/docs/image-transformations/store%0A     *%0A     * @param storeOptions configure where and how your file is stored%0A     * @return new %7B@link FileLink FileLink%7D pointing to the file%0A     * @throws IOException if a network error occurs, handle doesn't exist, or security is invalid%0A     */%0A
     public FileL
@@ -1778,32 +1778,34 @@
 Options == null)
+ %7B
 %0A            sto
@@ -1832,24 +1832,34 @@
 eOptions();%0A
+        %7D%0A
         addT
@@ -2006,24 +2006,26 @@
 Key != null)
+ %7B
 %0A           
@@ -2119,21 +2119,25 @@
 %0A       
+ %7D
  else
+ %7B
 %0A       
@@ -2211,16 +2211,26 @@
 .body();
+%0A        %7D
 %0A%0A      
@@ -2334,32 +2334,257 @@
 curity);%0A    %7D%0A%0A
+    /**%0A     * Add a new transformation to the chain.%0A     * Tasks are executed in the order they are added.%0A     *%0A     * @param task any one of the available %7B@link ImageTransformTask ImageTransformTask%7D subclasses%0A     */%0A
     public Image
@@ -2653,16 +2653,18 @@
 == null)
+ %7B
 %0A       
@@ -2747,16 +2747,26 @@
 form%22);%0A
+        %7D%0A
         

Fix linter warnings for ImageTransform