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.Utf8String;
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 DeviceContract extends Contract {
    private static final String BINARY = "60008054600160a060020a0319163317905560c0604052601060808190527f64657669636520696e666f20746573740000000000000000000000000000000060a090815261005091600191906100ba565b506040805180820190915260128082527f7072697661637920706f6c696379202e2e2e00000000000000000000000000006020909201918252610095916002916100ba565b5060048054600160a060020a031916331790553480156100b457600080fd5b50610155565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100fb57805160ff1916838001178555610128565b82800160010185558215610128579182015b8281111561012857825182559160200191906001019061010d565b50610134929150610138565b5090565b61015291905b80821115610134576000815560010161013e565b90565b610692806101646000396000f3006080604052600436106100a35763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663320f201e81146100a857806341c0e1b51461010357806364beeaea146101185780637b6fe4ce146101495780638da5cb5b1461015e578063a3f09ad614610173578063a3f6774d14610194578063acc90f79146101b5578063dc0453041461020e578063eec56ecf14610298575b600080fd5b3480156100b457600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526101019436949293602493928401919081908401838280828437509497506102ad9650505050505050565b005b34801561010f57600080fd5b50610101610304565b34801561012457600080fd5b5061012d610329565b60408051600160a060020a039092168252519081900360200190f35b34801561015557600080fd5b5061012d610339565b34801561016a57600080fd5b5061012d610348565b34801561017f57600080fd5b50610101600160a060020a0360043516610357565b3480156101a057600080fd5b50610101600160a060020a03600435166103b4565b3480156101c157600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526101019436949293602493928401919081908401838280828437509497506104929650505050505050565b34801561021a57600080fd5b506102236104e9565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561025d578181015183820152602001610245565b50505050905090810190601f16801561028a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156102a457600080fd5b50610223610576565b600054600160a060020a031633146102c457600080fd5b80516102d79060029060208401906105ce565b506040517f15c0693e714f552c7a83e9adacc650edf641b7f02ed0addff6a555e6918d36c690600090a150565b600054600160a060020a0316331461031b57600080fd5b600054600160a060020a0316ff5b600354600160a060020a03165b90565b600354600160a060020a031681565b600054600160a060020a031681565b600054600160a060020a031633148061037a5750600454600160a060020a031633145b151561038557600080fd5b6004805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600454600090600160a060020a038381169116141561048e57506003805473ffffffffffffffffffffffffffffffffffffffff191633908117909155604080517fbb62cf220000000000000000000000000000000000000000000000000000000081529051829163bb62cf2291600480830192600092919082900301818387803b15801561044157600080fd5b505af1158015610455573d6000803e3d6000fd5b5050604051600160a060020a03851692507f50522c7af4430ad2fb94eafa5822bb37d002c3278ea05da94aed3dd477b1c6959150600090a25b5050565b600054600160a060020a031633146104a957600080fd5b80516104bc9060019060208401906105ce565b506040517f579d1198506d9238b88e8ae90b599aa3b8e84aeca6151deb26d9adc89541f31790600090a150565b60018054604080516020600284861615610100026000190190941693909304601f8101849004840282018401909252818152929183018282801561056e5780601f106105435761010080835404028352916020019161056e565b820191906000526020600020905b81548152906001019060200180831161055157829003601f168201915b505050505081565b6002805460408051602060018416156101000260001901909316849004601f8101849004840282018401909252818152929183018282801561056e5780601f106105435761010080835404028352916020019161056e565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061060f57805160ff191683800117855561063c565b8280016001018555821561063c579182015b8281111561063c578251825591602001919060010190610621565b5061064892915061064c565b5090565b61033691905b8082111561064857600081556001016106525600a165627a7a72305820eda9438391c70d619cd5e7c2af9c1671744ea5c985a854f510d1a27d9a89faf40029";

    public static final String FUNC_SETPP = "setpp";

    public static final String FUNC_KILL = "kill";

    public static final String FUNC_GETBONDDEVICE = "getBondDevice";

    public static final String FUNC_BINDED = "binded";

    public static final String FUNC_OWNER = "owner";

    public static final String FUNC_SETBUYER = "setBuyer";

    public static final String FUNC_BINDREQ = "bindReq";

    public static final String FUNC_SETDEVICEINFO = "setdeviceinfo";

    public static final String FUNC_DEVICEINFO = "deviceInfo";

    public static final String FUNC_PRIVACYPOLICY = "privacypolicy";

    public static final Event INFOUPDATE_EVENT = new Event("InfoUpdate", 
            Arrays.<TypeReference<?>>asList());
    ;

    public static final Event POLICYUPDATE_EVENT = new Event("policyUpdate", 
            Arrays.<TypeReference<?>>asList());
    ;

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

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

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

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

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

    public RemoteCall<TransactionReceipt> setpp(String pp) {
        final Function function = new Function(
                FUNC_SETPP, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(pp)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

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

    public RemoteCall<String> getBondDevice() {
        final Function function = new Function(FUNC_GETBONDDEVICE, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
        return executeRemoteCallSingleValueReturn(function, String.class);
    }

    public RemoteCall<String> binded() {
        final Function function = new Function(FUNC_BINDED, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
        return executeRemoteCallSingleValueReturn(function, String.class);
    }

    public RemoteCall<String> owner() {
        final Function function = new Function(FUNC_OWNER, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}));
        return executeRemoteCallSingleValueReturn(function, String.class);
    }

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

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

    public RemoteCall<TransactionReceipt> setdeviceinfo(String info) {
        final Function function = new Function(
                FUNC_SETDEVICEINFO, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(info)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public RemoteCall<String> deviceInfo() {
        final Function function = new Function(FUNC_DEVICEINFO, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
        return executeRemoteCallSingleValueReturn(function, String.class);
    }

    public RemoteCall<String> privacypolicy() {
        final Function function = new Function(FUNC_PRIVACYPOLICY, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
        return executeRemoteCallSingleValueReturn(function, String.class);
    }

    public List<InfoUpdateEventResponse> getInfoUpdateEvents(TransactionReceipt transactionReceipt) {
        List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(INFOUPDATE_EVENT, transactionReceipt);
        ArrayList<InfoUpdateEventResponse> responses = new ArrayList<InfoUpdateEventResponse>(valueList.size());
        for (Contract.EventValuesWithLog eventValues : valueList) {
            InfoUpdateEventResponse typedResponse = new InfoUpdateEventResponse();
            typedResponse.log = eventValues.getLog();
            responses.add(typedResponse);
        }
        return responses;
    }

    public Flowable<InfoUpdateEventResponse> infoUpdateEventFlowable(EthFilter filter) {
        return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, InfoUpdateEventResponse>() {
            @Override
            public InfoUpdateEventResponse apply(Log log) {
                Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(INFOUPDATE_EVENT, log);
                InfoUpdateEventResponse typedResponse = new InfoUpdateEventResponse();
                typedResponse.log = log;
                return typedResponse;
            }
        });
    }

    public Flowable<InfoUpdateEventResponse> infoUpdateEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(INFOUPDATE_EVENT));
        return infoUpdateEventFlowable(filter);
    }

    public List<PolicyUpdateEventResponse> getPolicyUpdateEvents(TransactionReceipt transactionReceipt) {
        List<Contract.EventValuesWithLog> valueList = extractEventParametersWithLog(POLICYUPDATE_EVENT, transactionReceipt);
        ArrayList<PolicyUpdateEventResponse> responses = new ArrayList<PolicyUpdateEventResponse>(valueList.size());
        for (Contract.EventValuesWithLog eventValues : valueList) {
            PolicyUpdateEventResponse typedResponse = new PolicyUpdateEventResponse();
            typedResponse.log = eventValues.getLog();
            responses.add(typedResponse);
        }
        return responses;
    }

    public Flowable<PolicyUpdateEventResponse> policyUpdateEventFlowable(EthFilter filter) {
        return web3j.ethLogFlowable(filter).map(new io.reactivex.functions.Function<Log, PolicyUpdateEventResponse>() {
            @Override
            public PolicyUpdateEventResponse apply(Log log) {
                Contract.EventValuesWithLog eventValues = extractEventParametersWithLog(POLICYUPDATE_EVENT, log);
                PolicyUpdateEventResponse typedResponse = new PolicyUpdateEventResponse();
                typedResponse.log = log;
                return typedResponse;
            }
        });
    }

    public Flowable<PolicyUpdateEventResponse> policyUpdateEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(POLICYUPDATE_EVENT));
        return policyUpdateEventFlowable(filter);
    }

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

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

    public Flowable<ReceiveBindRequestEventResponse> receiveBindRequestEventFlowable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
        EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
        filter.addSingleTopic(EventEncoder.encode(RECEIVEBINDREQUEST_EVENT));
        return receiveBindRequestEventFlowable(filter);
    }

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

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

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

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

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

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

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

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

    public static class InfoUpdateEventResponse {
        public Log log;
    }

    public static class PolicyUpdateEventResponse {
        public Log log;
    }

    public static class ReceiveBindRequestEventResponse {
        public Log log;

        public String requester;
    }
}
