// Path: src/main/java/com/github/vedenin/codingchallenge/common/CurrencyEnum.java
// public enum CurrencyEnum {
//     EUR("EUR", "Euro (EUR)"),
//     USD("USD", "US Dollar (USD)"),
//     GBP("GBP", "British Pound (GBP)"),
//     NZD("NZD", "New Zealand Dollar (NZD)"),
//     AUD("AUD", "Australian Dollar (AUD)"),
//     JPY("JPY", "Japanese Yen (JPY)"),
//     HUF("HUF", "Hungarian Forint (HUF)"),
//     RUB("RUB", "Russian Ruble (RUB)"),
//     PLN("PLN", "Polish Zloty (PLN)");
//     private final String code;
//     private final String description;
// 
//     CurrencyEnum(String code, String description) {
//         this.code = code;
//         this.description = description;
//     }
// 
//     public String getCode() {
//         return code;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// }
// 
// Path: src/main/java/com/github/vedenin/codingchallenge/exceptions/ConverterException.java
// public class ConverterException extends RuntimeException {
//     public ConverterException() {
//     }
// 
//     public ConverterException(String message) {
//         super(message);
//     }
// 
//     public ConverterException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ConverterException(Throwable cause) {
//         super(cause);
//     }
// 
//     public ConverterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }
// 
// Path: src/main/java/com/github/vedenin/codingchallenge/restclient/RestClient.java
// public interface RestClient {
//     BigDecimal getCurrentExchangeRates(CurrencyEnum currecnyFrom, CurrencyEnum currecnyTo);
//     BigDecimal getHistoricalExchangeRates(CurrencyEnum currencyFrom, CurrencyEnum currencyTo, Calendar calendar);
// }


import com.github.vedenin.codingchallenge.common.CurrencyEnum;
import com.github.vedenin.codingchallenge.exceptions.ConverterException;
import com.github.vedenin.codingchallenge.restclient.RestClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import java.math.BigDecimal;
import java.util.Calendar;
package com.github.vedenin.codingchallenge.converter;



/**
 * Created by vvedenin on 2/9/2017.
 */
@Service
public class CurrencyConvectorDefault implements CurrencyConvector {
    @Inject
    @Qualifier("FaultTolerant")
    RestClient restClient;


    private BigDecimal getConvertingCurrentValue(BigDecimal amount, CurrencyEnum currencyFrom, CurrencyEnum currencyTo) {
        return amount.multiply(restClient.getCurrentExchangeRates(currencyFrom, currencyTo));
    }

    private BigDecimal getConvertingHistoricalValue(BigDecimal amount, CurrencyEnum currencyFrom, CurrencyEnum currencyTo, Calendar calendar) {
        return amount.multiply(restClient.getHistoricalExchangeRates(currencyFrom, currencyTo, calendar));
    }

    @Override
    public BigDecimal getConvertingValue(Boolean isHistory, BigDecimal amount, CurrencyEnum currencyFrom,
                                         CurrencyEnum currencyTo, Calendar calendar) {
        if(isHistory) {
            if(calendar != null) {
                return getConvertingHistoricalValue(amount, currencyFrom, currencyTo, calendar);
            } else {
// Path: src/main/java/com/github/vedenin/codingchallenge/common/CurrencyEnum.java
// public enum CurrencyEnum {
//     EUR("EUR", "Euro (EUR)"),
//     USD("USD", "US Dollar (USD)"),
//     GBP("GBP", "British Pound (GBP)"),
//     NZD("NZD", "New Zealand Dollar (NZD)"),
//     AUD("AUD", "Australian Dollar (AUD)"),
//     JPY("JPY", "Japanese Yen (JPY)"),
//     HUF("HUF", "Hungarian Forint (HUF)"),
//     RUB("RUB", "Russian Ruble (RUB)"),
//     PLN("PLN", "Polish Zloty (PLN)");
//     private final String code;
//     private final String description;
// 
//     CurrencyEnum(String code, String description) {
//         this.code = code;
//         this.description = description;
//     }
// 
//     public String getCode() {
//         return code;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// }
// 
// Path: src/main/java/com/github/vedenin/codingchallenge/exceptions/ConverterException.java
// public class ConverterException extends RuntimeException {
//     public ConverterException() {
//     }
// 
//     public ConverterException(String message) {
//         super(message);
//     }
// 
//     public ConverterException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public ConverterException(Throwable cause) {
//         super(cause);
//     }
// 
//     public ConverterException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
//         super(message, cause, enableSuppression, writableStackTrace);
//     }
// }
// 
// Path: src/main/java/com/github/vedenin/codingchallenge/restclient/RestClient.java
// public interface RestClient {
//     BigDecimal getCurrentExchangeRates(CurrencyEnum currecnyFrom, CurrencyEnum currecnyTo);
//     BigDecimal getHistoricalExchangeRates(CurrencyEnum currencyFrom, CurrencyEnum currencyTo, Calendar calendar);
// }


// Path: src/main/java/com/github/vedenin/codingchallenge/converter/CurrencyConvectorDefault.java
import com.github.vedenin.codingchallenge.common.CurrencyEnum;
import com.github.vedenin.codingchallenge.exceptions.ConverterException;
import com.github.vedenin.codingchallenge.restclient.RestClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
import java.math.BigDecimal;
import java.util.Calendar;

package com.github.vedenin.codingchallenge.converter;



/**
 * Created by vvedenin on 2/9/2017.
 */
@Service
public class CurrencyConvectorDefault implements CurrencyConvector {
    @Inject
    @Qualifier("FaultTolerant")
    RestClient restClient;


    private BigDecimal getConvertingCurrentValue(BigDecimal amount, CurrencyEnum currencyFrom, CurrencyEnum currencyTo) {
        return amount.multiply(restClient.getCurrentExchangeRates(currencyFrom, currencyTo));
    }

    private BigDecimal getConvertingHistoricalValue(BigDecimal amount, CurrencyEnum currencyFrom, CurrencyEnum currencyTo, Calendar calendar) {
        return amount.multiply(restClient.getHistoricalExchangeRates(currencyFrom, currencyTo, calendar));
    }

    @Override
    public BigDecimal getConvertingValue(Boolean isHistory, BigDecimal amount, CurrencyEnum currencyFrom,
                                         CurrencyEnum currencyTo, Calendar calendar) {
        if(isHistory) {
            if(calendar != null) {
                return getConvertingHistoricalValue(amount, currencyFrom, currencyTo, calendar);
            } else {
                throw new ConverterException("'Date' must be filled in historical convection");