package edu.prlab.tyler.iotgateway.contract;

import io.reactivex.Flowable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.web3j.abi.EventEncoder;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Address;
import org.web3j.abi.datatypes.Event;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.generated.Uint256;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.request.EthFilter;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;
import org.web3j.tx.gas.ContractGasProvider;

/**
 * <p>Auto generated code.
 * <p><strong>Do not modify!</strong>
 * <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
 * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 
 * <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
 *
 * <p>Generated with web3j version 4.2.0.
 */
public class GatewayContract extends Contract {
    private static final String BINARY = "608060405234801561001057600080fd5b5060008054600160a060020a031916331781556001556103dd806100356000396000f30060806040526004361061006c5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663052c45568114610071578063303877bf146100945780635fa8724b146100c8578063b5474550146100e0578063bb62cf2214610107575b600080fd5b34801561007d57600080fd5b50610092600160a060020a036004351661011c565b005b3480156100a057600080fd5b506100ac600435610283565b60408051600160a060020a039092168252519081900360200190f35b3480156100d457600080fd5b506100926004356102d9565b3480156100ec57600080fd5b506100f561031e565b60408051918252519081900360200190f35b34801561011357600080fd5b50610092610324565b6000805481908190600160a060020a0316331461013857600080fd5b60019250600091505b60015482101561019557600082815260026020526040902054600160a060020a038581169116141561018a57600082815260026020526040902060019081018190559250610195565b600190910190610141565b600183151514156101ff57604080518082018252600160a060020a038681168252600160208084018281528254600090815260029092529490209251835473ffffffffffffffffffffffffffffffffffffffff191692169190911782559151908201558054810190555b5060008054604080517fa3f6774d000000000000000000000000000000000000000000000000000000008152600160a060020a039283166004820152905186939284169263a3f6774d926024808201939182900301818387803b15801561026557600080fd5b505af1158015610279573d6000803e3d6000fd5b5050505050505050565b6000600154821115610297575060006102d4565b60008281526002602081905260409091206001015414156102d05750600081815260026020526040902054600160a060020a03166102d4565b5060005b919050565b600054600160a060020a031633146102f057600080fd5b6000811015801561030357506001548111155b1561031b576000818152600260205260408120600101555b50565b60015481565b60005b60015481101561031b57600081815260026020526040902054600160a060020a03163314156103a957600081815260026020526040902060019081015414156103a9576000818152600260208190526040808320600101919091555133917f2e3c42cbe8d40e1905dccdfd129295bf0d4a7ee9d8e28fc582619541c0a0294f91a25b6001016103275600a165627a7a72305820273afc7c3ee3e470171301e48897c667293b777050ec35e34d519b7c1e4e340e0029";

    public static final String FUNC_BINDREQUEST = "bindRequest";

    public static final String FUNC_GETDEVICEADDRESS = "getDeviceAddress";

    public static final String FUNC_REMOVEDEVICE = "removeDevice";

    public static final String FUNC_NUMDEVICES = "numDevices";

    public static final String FUNC_BINDRESPONSE = "bindResponse";

    public static final Event RECEIVEBINDRESPONSE_EVENT = new Event("receiveBindResponse", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>(true) {}));
    ;

    @Deprecated
    protected GatewayContract(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    protected GatewayContract(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
        super(BINARY, contractAddress, web3j, credentials, contractGasProvider);
    }

    @Deprecated
    protected GatewayContract(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    protected GatewayContract(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
        super(BINARY, contractAddress, web3j, transactionManager, contractGasProvider);
    }

    public RemoteCall<TransactionReceipt> bindRequest(String dm) {
        final Function function = new Function(
                FUNC_BINDREQUEST, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(dm)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<String> getDeviceAddress(BigInteger i) {
        final Function function = new Function(FUNC_GETDEVICEADDRESS, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(i)), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
        return executeRemoteCallSingleValueReturn(function, String.class);
    }

    public RemoteCall<TransactionReceipt> removeDevice(BigInteger i) {
        final Function function = new Function(
                FUNC_REMOVEDEVICE, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(i)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<BigInteger> numDevices() {
        final Function function = new Function(FUNC_NUMDEVICES, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
        return executeRemoteCallSingleValueReturn(function, BigInteger.class);
    }

    public RemoteCall<TransactionReceipt> bindResponse() {
        final Function function = new Function(
                FUNC_BINDRESPONSE, 
                Arrays.<Type>asList(), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public List<ReceiveBindResponseEventResponse> getReceiveBindResponseEvents(TransactionReceipt transactionReceipt) {
        List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(RECEIVEBINDRESPONSE_EVENT, transactionReceipt);
        ArrayList<ReceiveBindResponseEventResponse> responses = new ArrayList<ReceiveBindResponseEventResponse>(valueList.size());
        for (Contract.EventValuesWithLog eventValues : valueList) {
            ReceiveBindResponseEventResponse typedResponse = new ReceiveBindResponseEventResponse();
            typedResponse.log = eventValues.getLog();
            typedResponse.dm = (String) eventValues.getIndexedValues().get(0).getValue();
            responses.add(typedResponse);
        }
        return responses;
    }

    public Flowable<ReceiveBindResponseEventResponse> receiveBindResponseEventFlowable(EthFilter filter) {
        return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, ReceiveBindResponseEventResponse>() {
            @Override
            public ReceiveBindResponseEventResponse apply(Log log) {
                Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(RECEIVEBINDRESPONSE_EVENT, log);
                ReceiveBindResponseEventResponse typedResponse = new ReceiveBindResponseEventResponse();
                typedResponse.log = log;
                typedResponse.dm = (String) eventValues.getIndexedValues().get(0).getValue();
                return typedResponse;
            }
        });
    }

    public Flowable<ReceiveBindResponseEventResponse> receiveBindResponseEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(RECEIVEBINDRESPONSE_EVENT));
        return receiveBindResponseEventFlowable(filter);
    }

    @Deprecated
    public static GatewayContract load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return new GatewayContract(contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    @Deprecated
    public static GatewayContract load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return new GatewayContract(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    public static GatewayContract load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
        return new GatewayContract(contractAddress, web3j, credentials, contractGasProvider);
    }

    public static GatewayContract load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
        return new GatewayContract(contractAddress, web3j, transactionManager, contractGasProvider);
    }

    public static RemoteCall<GatewayContract> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
        return deployRemoteCall(GatewayContract.class, web3j, credentials, contractGasProvider, BINARY, "");
    }

    public static RemoteCall<GatewayContract> deploy(Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
        return deployRemoteCall(GatewayContract.class, web3j, transactionManager, contractGasProvider, BINARY, "");
    }

    @Deprecated
    public static RemoteCall<GatewayContract> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(GatewayContract.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
    }

    @Deprecated
    public static RemoteCall<GatewayContract> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(GatewayContract.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
    }

    public static class ReceiveBindResponseEventResponse {
        public Log log;

        public String dm;
    }
}
