package com.filestack;

import com.filestack.transforms.TransformTask;
import com.filestack.util.Util;
import java.util.HashMap;
import java.util.Map;
import okhttp3.RequestBody;

/** Configure storage options for uploads and transformation stores. */
public class StorageOptions {
  private String access;
  private Boolean base64Decode;
  private String container;
  private String filename;
  private String location;
  private String path;
  private String region;

  public StorageOptions() { }

  /** Get these options as a task. */
  public TransformTask getAsTask() {
    TransformTask task = new TransformTask("store");
    addToTask(task);
    return task;
  }

  /** Add these options to an existing task. */
  public void addToTask(TransformTask task) {
    task.addOption("access", access);
    task.addOption("base64decode", base64Decode);
    task.addOption("container", container);
    task.addOption("filename", filename);
    task.addOption("location", location);
    task.addOption("path", path);
    task.addOption("region", region);
  }

  /** Get these options as a part map to use for uploads. */
  public Map<String, RequestBody> getAsPartMap() {
    HashMap<String, RequestBody> map = new HashMap<>();
    addToMap(map, "store_access", access);
    addToMap(map, "store_container", container);
    addToMap(map, "store_location", location != null ? location : "s3");
    addToMap(map, "store_path", path);
    addToMap(map, "store_region", region);
    return map;
  }

  private static void addToMap(Map<String, RequestBody> map, String key, String value) {
    if (value != null) {
      map.put(key, Util.createStringPart(value));
    }
  }

  public static class Builder {
    private String access;
    private Boolean base64Decode;
    private String container;
    private String filename;
    private String location;
    private String path;
    private String region;

    public Builder access(String access) {
      this.access = access;
      return this;
    }

    public Builder base64Decode(boolean base64Decode) {
      this.base64Decode = base64Decode;
      return this;
    }

    public Builder container(String container) {
      this.container = container;
      return this;
    }

    public Builder filename(String filename) {
      this.filename = filename;
      return this;
    }

    public Builder location(String location) {
      this.location = location;
      return this;
    }

    public Builder path(String path) {
      this.path = path;
      return this;
    }

    public Builder region(String region) {
      this.region = region;
      return this;
    }

    /**
     * Builds new {@link StorageOptions}.
     */
    public StorageOptions build() {
      StorageOptions building = new StorageOptions();
      building.access = access;
      building.base64Decode = base64Decode;
      building.container = container;
      building.filename = filename;
      building.location = location;
      building.path = path;
      building.region = region;
      return building;
    }
  }
}

@@ -140,24 +140,50 @@
 a.util.Map;%0A
+import okhttp3.MediaType;%0A
 import okhtt
@@ -483,24 +483,54 @@
 ring region;
+%0A  private String contentType;
 %0A%0A  public S
@@ -1531,18 +1531,284 @@
     
-return map
+addToMap(map, %22mimetype%22, contentType);%0A    return map;%0A  %7D%0A%0A  public MediaType getMediaType() %7B%0A    return MediaType.parse(contentType);%0A  %7D%0A%0A  public boolean hasContentType() %7B%0A    return contentType != null;%0A  %7D%0A%0A  public Builder newBuilder() %7B%0A    return new Builder(this)
 ;%0A  
@@ -2217,16 +2217,481 @@
  region;
+%0A    private String contentType;%0A%0A    public Builder() %7B %7D%0A%0A    /** Create a new builder using an existing options config. */%0A    public Builder(StorageOptions existing) %7B%0A      access = existing.access;%0A      base64Decode = existing.base64Decode;%0A      container = existing.container;%0A      filename = existing.filename;%0A      location = existing.location;%0A      path = existing.path;%0A      region = existing.region;%0A      contentType = existing.contentType;%0A    %7D
 %0A%0A    pu
@@ -3404,24 +3404,141 @@
 his;%0A    %7D%0A%0A
+    public Builder contentType(String contentType) %7B%0A      this.contentType = contentType;%0A      return this;%0A    %7D%0A%0A
     /**%0A    
@@ -3911,32 +3911,74 @@
 egion = region;%0A
+      building.contentType = contentType;%0A
       return bui

Move content type setting into StorageOptions