// Path: completable-future-demo/src/org/iproduct/cfdemo/Currency.java
// public enum Currency {
// 	BGN, GBP, EUR, USD
// }


import static org.iproduct.cfdemo.Currency.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

package org.iproduct.cfdemo;



public class CompletableFutureComposition {

	public void testlCompletableFutureComposition() throws InterruptedException, ExecutionException {
		Double priceInEuro = CompletableFuture.supplyAsync(() -> getStockPrice("GOOGL"))
			.thenCombine(CompletableFuture.supplyAsync(() -> getExchangeRate(USD, EUR)), this::convertPrice)
			.exceptionally(throwable -> {
				System.out.println("Error: " + throwable.getMessage());
				return -1d;
			}).get();
		
		System.out.println("GOOGL stock price in Euro: " + priceInEuro );
	}
	
	public Price getStockPrice(String stockSymbol) {
		switch (stockSymbol) {
		case "GOOGL" : return new Price(950.28, USD);
		case "AAPL" : return new Price(148.96, USD);
		case "MSFT" : return new Price(69.00, USD);
		case "FB" : return new Price(150.24, USD);
		default: 
			throw new RuntimeException("Stocks symbol not found.");
		}
	}
		

// Path: completable-future-demo/src/org/iproduct/cfdemo/Currency.java
// public enum Currency {
// 	BGN, GBP, EUR, USD
// }


// Path: completable-future-demo/src/org/iproduct/cfdemo/CompletableFutureComposition.java
import static org.iproduct.cfdemo.Currency.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

package org.iproduct.cfdemo;



public class CompletableFutureComposition {

	public void testlCompletableFutureComposition() throws InterruptedException, ExecutionException {
		Double priceInEuro = CompletableFuture.supplyAsync(() -> getStockPrice("GOOGL"))
			.thenCombine(CompletableFuture.supplyAsync(() -> getExchangeRate(USD, EUR)), this::convertPrice)
			.exceptionally(throwable -> {
				System.out.println("Error: " + throwable.getMessage());
				return -1d;
			}).get();
		
		System.out.println("GOOGL stock price in Euro: " + priceInEuro );
	}
	
	public Price getStockPrice(String stockSymbol) {
		switch (stockSymbol) {
		case "GOOGL" : return new Price(950.28, USD);
		case "AAPL" : return new Price(148.96, USD);
		case "MSFT" : return new Price(69.00, USD);
		case "FB" : return new Price(150.24, USD);
		default: 
			throw new RuntimeException("Stocks symbol not found.");
		}
	}
		

	public Double getExchangeRate(Currency from, Currency to) {
