package it.enea.cruise.controller;

import org.springframework.web.bind.annotation.RestController;
/*import org.web3j.protocol.core.methods.response.EthAccounts;
import org.web3j.protocol.core.methods.response.EthBlockNumber;
import org.web3j.protocol.core.methods.response.EthGetBalance;
import org.web3j.protocol.core.methods.response.EthGetTransactionCount;

import org.web3j.contracts.eip20.generated.ERC20;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;*/

@RestController
public class BCRestController {

    /*@Autowired
    Web3Service web3Service;

    @RequestMapping(value = "getBlock", method = RequestMethod.GET)
    public Future<ResponseTransfer> getBlock() {
        ResponseTransfer responseTransfer = new ResponseTransfer();
        Instant start = TimeHelper.start();

        return CompletableFuture.supplyAsync(() -> {
            try {
                EthBlockNumber result = web3Service.getBlockNumber();
                responseTransfer.setMessage(result.getBlockNumber().toString());
            } catch (Exception e) {
                responseTransfer.setMessage("Eccezione generica " + e.getLocalizedMessage());
            }
            return responseTransfer;
        }).thenApplyAsync(result -> {
            result.setPerformance(TimeHelper.stop(start));
            return result;
        });
    }

    @RequestMapping(value = "getAccounts", method = RequestMethod.GET)
    public Future<ResponseTransfer> getAccounts() {
        ResponseTransfer responseTransfer = new ResponseTransfer();
        Instant start = TimeHelper.start();

        return CompletableFuture.supplyAsync(() -> {
            try {
                EthAccounts result = web3Service.getEthAccounts();
                responseTransfer.setMessage(result.getAccounts().toString());
            } catch (Exception e) {
                responseTransfer.setMessage("Eccezione generica");
            }
            return responseTransfer;

        }).thenApplyAsync(result -> {
            result.setPerformance(TimeHelper.stop(start));
            return result;
        });
    }

    @RequestMapping(value = "getTransactions", method = RequestMethod.GET)
    public Future<ResponseTransfer> getTransactions() {
        ResponseTransfer responseTransfer = new ResponseTransfer();
        Instant start = TimeHelper.start();
        return CompletableFuture.supplyAsync(() -> {
            try {
                EthGetTransactionCount result = web3Service.getTransactionCount();
                responseTransfer.setMessage(result.getResult().toString());
            } catch (Exception e) {
                responseTransfer.setMessage("Eccezione generica");
            }
            return responseTransfer;
        }).thenApplyAsync(result -> {
            result.setPerformance(TimeHelper.stop(start));
            return result;
        });
    }

    @RequestMapping(value = "getBalance", method = RequestMethod.GET)
    public Future<ResponseTransfer> getBalance() {
        ResponseTransfer responseTransfer = new ResponseTransfer();
        Instant start = TimeHelper.start();
        return CompletableFuture.supplyAsync(() -> {
            try {
                EthGetBalance result = web3Service.getEthBalance();
                
                responseTransfer.setMessage(result.toString() + " " + result.getBalance());
            } catch (Exception e) {
                responseTransfer.setMessage("Eccezione generica: " + e.toString());
            }
            return responseTransfer;
        }).thenApplyAsync(result -> {
            result.setPerformance(TimeHelper.stop(start));
            return result;
        });
    }
    
    
    @RequestMapping(value = "getTKBalance", method = RequestMethod.GET)
    public BigInteger getTKBalanceOf(final String contractAddress, final String walletAddress, final Integer communityId) throws Exception {
        BigInteger balanceOf = web3Service.getTKBalance(contractAddress, walletAddress, communityId);
        return balanceOf;
    }*/
}