// Path: bitcoin/src/main/java/de/rainu/alexa/bitcoin/model/BitcoinCurse.java
// public class BitcoinCurse {
//   private DateTime date;
//   private Double coin;
//   private Double euro;
// 
//   public BitcoinCurse(DateTime date, Double coin, Double euro) {
//     this.date = date;
//     this.coin = coin;
//     this.euro = euro;
//   }
// 
//   public DateTime getDate() {
//     return date;
//   }
// 
//   public Double getCoin() {
//     return coin;
//   }
// 
//   public Double getEuro() {
//     return euro;
//   }
// 
//   @Override
//   public boolean equals(Object o) {
//     if (this == o) {
//       return true;
//     }
//     if (!(o instanceof BitcoinCurse)) {
//       return false;
//     }
// 
//     BitcoinCurse that = (BitcoinCurse) o;
// 
//     if (date != null ? !date.equals(that.date) : that.date != null) {
//       return false;
//     }
//     if (coin != null ? !coin.equals(that.coin) : that.coin != null) {
//       return false;
//     }
//     return euro != null ? euro.equals(that.euro) : that.euro == null;
//   }
// 
//   @Override
//   public int hashCode() {
//     int result = date != null ? date.hashCode() : 0;
//     result = 31 * result + (coin != null ? coin.hashCode() : 0);
//     result = 31 * result + (euro != null ? euro.hashCode() : 0);
//     return result;
//   }
// 
//   @Override
//   public String toString() {
//     return "@" + date + ": " +coin + "bc <=> " + euro + "€";
//   }
// }


import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.rainu.alexa.bitcoin.model.BitcoinCurse;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.format.DateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
package de.rainu.alexa.bitcoin.service.provider;


@Service
public class RestCurseProvider implements BitcoinCurseProvider {
  private static final Logger log = LoggerFactory.getLogger(RestCurseProvider.class);

  public static final String ENDPOINT = "https://bitcoinapi.de/widget/current-btc-price/rate.json?culture=de";

  private static final Pattern MONEY_PATTERN = Pattern.compile("([0-9\\.,]*)");

  @Autowired
  RestTemplate rest;

  @Autowired
  ObjectMapper mapper;

  DateTime lastCall;
  BitcoinCurse lastCurse;

  @Override
  public BitcoinCurse getCurrentCurse() {
    if(lastCurse == null || ttlIsOver()) {
      try {
        lastCurse = requestBitcoinCurse();
      } catch (IOException e) {
        log.error("Error while request bitcoin!", e);
        lastCurse = new BitcoinCurse(DateTime.now().minusDays(1), null, null);
      }
      lastCall = DateTime.now();
    }

    return lastCurse;
  }

  private boolean ttlIsOver() {
    return Math.abs(new Duration(DateTime.now(), lastCall).getStandardMinutes()) >= 1;
  }

// Path: bitcoin/src/main/java/de/rainu/alexa/bitcoin/model/BitcoinCurse.java
// public class BitcoinCurse {
//   private DateTime date;
//   private Double coin;
//   private Double euro;
// 
//   public BitcoinCurse(DateTime date, Double coin, Double euro) {
//     this.date = date;
//     this.coin = coin;
//     this.euro = euro;
//   }
// 
//   public DateTime getDate() {
//     return date;
//   }
// 
//   public Double getCoin() {
//     return coin;
//   }
// 
//   public Double getEuro() {
//     return euro;
//   }
// 
//   @Override
//   public boolean equals(Object o) {
//     if (this == o) {
//       return true;
//     }
//     if (!(o instanceof BitcoinCurse)) {
//       return false;
//     }
// 
//     BitcoinCurse that = (BitcoinCurse) o;
// 
//     if (date != null ? !date.equals(that.date) : that.date != null) {
//       return false;
//     }
//     if (coin != null ? !coin.equals(that.coin) : that.coin != null) {
//       return false;
//     }
//     return euro != null ? euro.equals(that.euro) : that.euro == null;
//   }
// 
//   @Override
//   public int hashCode() {
//     int result = date != null ? date.hashCode() : 0;
//     result = 31 * result + (coin != null ? coin.hashCode() : 0);
//     result = 31 * result + (euro != null ? euro.hashCode() : 0);
//     return result;
//   }
// 
//   @Override
//   public String toString() {
//     return "@" + date + ": " +coin + "bc <=> " + euro + "€";
//   }
// }


// Path: bitcoin/src/main/java/de/rainu/alexa/bitcoin/service/provider/RestCurseProvider.java
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.rainu.alexa.bitcoin.model.BitcoinCurse;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.joda.time.format.DateTimeFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

package de.rainu.alexa.bitcoin.service.provider;


@Service
public class RestCurseProvider implements BitcoinCurseProvider {
  private static final Logger log = LoggerFactory.getLogger(RestCurseProvider.class);

  public static final String ENDPOINT = "https://bitcoinapi.de/widget/current-btc-price/rate.json?culture=de";

  private static final Pattern MONEY_PATTERN = Pattern.compile("([0-9\\.,]*)");

  @Autowired
  RestTemplate rest;

  @Autowired
  ObjectMapper mapper;

  DateTime lastCall;
  BitcoinCurse lastCurse;

  @Override
  public BitcoinCurse getCurrentCurse() {
    if(lastCurse == null || ttlIsOver()) {
      try {
        lastCurse = requestBitcoinCurse();
      } catch (IOException e) {
        log.error("Error while request bitcoin!", e);
        lastCurse = new BitcoinCurse(DateTime.now().minusDays(1), null, null);
      }
      lastCall = DateTime.now();
    }

    return lastCurse;
  }

  private boolean ttlIsOver() {
    return Math.abs(new Duration(DateTime.now(), lastCall).getStandardMinutes()) >= 1;
  }

  private BitcoinCurse requestBitcoinCurse() throws IOException {