// Path: model/src/main/java/com/coinbase/exchange/model/Candles.java
// public class Candles {
// 
//     List<Candle> candleList;
// 
//     public Candles(List<String[]> candles) {
//         this.candleList = candles.stream().map(Candle::new).collect(Collectors.toList());
//     }
// 
//     public List<Candle> getCandleList() {
//         return candleList;
//     }
// }
// 
// Path: model/src/main/java/com/coinbase/exchange/model/Granularity.java
// public enum Granularity {
//     ONE_DAY("1d"),
//     SIX_HOURS("6h"),
//     ONE_HOUR("1h"),
//     FIFTEEN_MIN("15m"),
//     FIVE_MIN("5m"),
//     ONE_MIN("1m");
// 
//     private String granularity;
// 
//     Granularity(String granularity) {
//         this.granularity = granularity;
//     }
// 
//     /**
//      * The granularity field must be one of the following values:
//      * {60, 300, 900, 3600, 21600, 86400}.
//      */
//     public String get(){
//         switch(granularity) {
//             case "1d": return "86400";
//             case "6h": return "21600";
//             case "1h": return "3600";
//             case "15m": return "900";
//             case "5m": return "300";
//             case "1m": return "60";
//         }
//         return "";
//     }
// }


import com.coinbase.exchange.api.exchange.CoinbaseExchange;
import com.coinbase.exchange.model.Candles;
import com.coinbase.exchange.model.Granularity;
import com.coinbase.exchange.model.Product;
import org.springframework.core.ParameterizedTypeReference;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.util.stream.Collectors.joining;
package com.coinbase.exchange.api.products;




/**
 * Created by robevansuk on 03/02/2017.
 */
public class ProductService {

    public static final String PRODUCTS_ENDPOINT = "/products";

    final CoinbaseExchange exchange;

    public ProductService(final CoinbaseExchange exchange) {
        this.exchange = exchange;
    }

    // no paged products necessary
    public List<Product> getProducts() {
        return exchange.getAsList(PRODUCTS_ENDPOINT, new ParameterizedTypeReference<Product[]>() {
        });
    }

    public Candles getCandles(String productId) {
        return new Candles(exchange.get(PRODUCTS_ENDPOINT + "/" + productId + "/candles", new ParameterizedTypeReference<List<String[]>>() {
        }));
    }

    public Candles getCandles(String productId, Map<String, String> queryParams) {
        StringBuffer url = new StringBuffer(PRODUCTS_ENDPOINT + "/" + productId + "/candles");
        if (queryParams != null && queryParams.size() != 0) {
            url.append("?");
            url.append(queryParams.entrySet().stream()
                    .map(entry -> entry.getKey() + "=" + entry.getValue())
                    .collect(joining("&")));
        }
        return new Candles(exchange.get(url.toString(), new ParameterizedTypeReference<List<String[]>>() {}));
    }

    /**
     * If either one of the start or end fields are not provided then both fields will be ignored.
     * If a custom time range is not declared then one ending now is selected.
     */
// Path: model/src/main/java/com/coinbase/exchange/model/Candles.java
// public class Candles {
// 
//     List<Candle> candleList;
// 
//     public Candles(List<String[]> candles) {
//         this.candleList = candles.stream().map(Candle::new).collect(Collectors.toList());
//     }
// 
//     public List<Candle> getCandleList() {
//         return candleList;
//     }
// }
// 
// Path: model/src/main/java/com/coinbase/exchange/model/Granularity.java
// public enum Granularity {
//     ONE_DAY("1d"),
//     SIX_HOURS("6h"),
//     ONE_HOUR("1h"),
//     FIFTEEN_MIN("15m"),
//     FIVE_MIN("5m"),
//     ONE_MIN("1m");
// 
//     private String granularity;
// 
//     Granularity(String granularity) {
//         this.granularity = granularity;
//     }
// 
//     /**
//      * The granularity field must be one of the following values:
//      * {60, 300, 900, 3600, 21600, 86400}.
//      */
//     public String get(){
//         switch(granularity) {
//             case "1d": return "86400";
//             case "6h": return "21600";
//             case "1h": return "3600";
//             case "15m": return "900";
//             case "5m": return "300";
//             case "1m": return "60";
//         }
//         return "";
//     }
// }


// Path: api/src/main/java/com/coinbase/exchange/api/products/ProductService.java
import com.coinbase.exchange.api.exchange.CoinbaseExchange;
import com.coinbase.exchange.model.Candles;
import com.coinbase.exchange.model.Granularity;
import com.coinbase.exchange.model.Product;
import org.springframework.core.ParameterizedTypeReference;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.util.stream.Collectors.joining;

package com.coinbase.exchange.api.products;




/**
 * Created by robevansuk on 03/02/2017.
 */
public class ProductService {

    public static final String PRODUCTS_ENDPOINT = "/products";

    final CoinbaseExchange exchange;

    public ProductService(final CoinbaseExchange exchange) {
        this.exchange = exchange;
    }

    // no paged products necessary
    public List<Product> getProducts() {
        return exchange.getAsList(PRODUCTS_ENDPOINT, new ParameterizedTypeReference<Product[]>() {
        });
    }

    public Candles getCandles(String productId) {
        return new Candles(exchange.get(PRODUCTS_ENDPOINT + "/" + productId + "/candles", new ParameterizedTypeReference<List<String[]>>() {
        }));
    }

    public Candles getCandles(String productId, Map<String, String> queryParams) {
        StringBuffer url = new StringBuffer(PRODUCTS_ENDPOINT + "/" + productId + "/candles");
        if (queryParams != null && queryParams.size() != 0) {
            url.append("?");
            url.append(queryParams.entrySet().stream()
                    .map(entry -> entry.getKey() + "=" + entry.getValue())
                    .collect(joining("&")));
        }
        return new Candles(exchange.get(url.toString(), new ParameterizedTypeReference<List<String[]>>() {}));
    }

    /**
     * If either one of the start or end fields are not provided then both fields will be ignored.
     * If a custom time range is not declared then one ending now is selected.
     */
    public Candles getCandles(String productId, Instant startTime, Instant endTime, Granularity granularity) {