// Path: src/main/java/com/coding4people/mosquitoreport/api/Env.java
// public class Env {
//     public final static Env instance = new Env();
//     
//     private Map<String, String> properties = Maps.newHashMap();
//     
//     public Optional<String> get(String key) {
//         return Optional.ofNullable(properties.getOrDefault(key, System.getenv(key)));
//     }
//     
//     public Env register(String key, String value) {
//         properties.put(key, value);
//         
//         return this;
//     }
// }


import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.InternalServerErrorException;
import org.imgscalr.Scalr;
import org.imgscalr.Scalr.Method;
import org.imgscalr.Scalr.Mode;
import com.coding4people.mosquitoreport.api.Env;
package com.coding4people.mosquitoreport.api.buckets;





@Singleton
public class PictureBucket extends Bucket {
    @Inject
    Env env;

    @Override
    protected String getBucketName() {
        return env.get("BUCKET_NAME_PICTURE").orElseThrow(() -> new IllegalArgumentException("Missing env var: BUCKET_NAME_PICTURE"));
    }

    // TODO make it parallel
    public Object put(String path, InputStream fileInputStream, Long contentLenght) {
        try {
            ByteArrayOutputStream buffer = bufferInputStream(fileInputStream);

            // TODO make it parallel
            uploadThumbnail(path, buffer, 480, 360);
            
            // TODO make it parallel
            return super.put(path, new ByteArrayInputStream(buffer.toByteArray()), Long.valueOf(buffer.size()));
        } catch (IOException e) {
            // TODO handle and log
            e.printStackTrace();

            throw new InternalServerErrorException("Error uploading image");
        }
    }
    
// Path: src/main/java/com/coding4people/mosquitoreport/api/Env.java
// public class Env {
//     public final static Env instance = new Env();
//     
//     private Map<String, String> properties = Maps.newHashMap();
//     
//     public Optional<String> get(String key) {
//         return Optional.ofNullable(properties.getOrDefault(key, System.getenv(key)));
//     }
//     
//     public Env register(String key, String value) {
//         properties.put(key, value);
//         
//         return this;
//     }
// }


// Path: src/main/java/com/coding4people/mosquitoreport/api/buckets/PictureBucket.java
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.InternalServerErrorException;
import org.imgscalr.Scalr;
import org.imgscalr.Scalr.Method;
import org.imgscalr.Scalr.Mode;
import com.coding4people.mosquitoreport.api.Env;

package com.coding4people.mosquitoreport.api.buckets;





@Singleton
public class PictureBucket extends Bucket {
    @Inject
    Env env;

    @Override
    protected String getBucketName() {
        return env.get("BUCKET_NAME_PICTURE").orElseThrow(() -> new IllegalArgumentException("Missing env var: BUCKET_NAME_PICTURE"));
    }

    // TODO make it parallel
    public Object put(String path, InputStream fileInputStream, Long contentLenght) {
        try {
            ByteArrayOutputStream buffer = bufferInputStream(fileInputStream);

            // TODO make it parallel
            uploadThumbnail(path, buffer, 480, 360);
            
            // TODO make it parallel
            return super.put(path, new ByteArrayInputStream(buffer.toByteArray()), Long.valueOf(buffer.size()));
        } catch (IOException e) {
            // TODO handle and log
            e.printStackTrace();

            throw new InternalServerErrorException("Error uploading image");
        }
    }
    
    public void uploadThumbnail(String path, ByteArrayOutputStream buffer, int width, int height) throws IOException {