import os
here = os.path.abspath(os.path.dirname(__file__))
os.environ['CLASSPATH'] = os.path.join(here, "sdk-2.0.8-uber.jar")
from jnius import autoclass, PythonJavaClass, java_method

JString = autoclass("java.lang.String")
JStandardCharsets = autoclass("java.nio.charset.StandardCharsets")

HederaReceiptStatusException = autoclass('com.hedera.hashgraph.sdk.HederaReceiptStatusException')
Delayer = autoclass('com.hedera.hashgraph.sdk.Delayer')
ContractDeleteTransaction = autoclass('com.hedera.hashgraph.sdk.ContractDeleteTransaction')
WithExecute = autoclass('com.hedera.hashgraph.sdk.WithExecute')
TokenDissociateTransaction = autoclass('com.hedera.hashgraph.sdk.TokenDissociateTransaction')
TokenMintTransaction = autoclass('com.hedera.hashgraph.sdk.TokenMintTransaction')
FeeSchedule = autoclass('com.hedera.hashgraph.sdk.FeeSchedule')
AccountInfoQuery = autoclass('com.hedera.hashgraph.sdk.AccountInfoQuery')
MirrorNode = autoclass('com.hedera.hashgraph.sdk.MirrorNode')
TokenUpdateTransaction = autoclass('com.hedera.hashgraph.sdk.TokenUpdateTransaction')
SemanticVersion = autoclass('com.hedera.hashgraph.sdk.SemanticVersion')
ContractFunctionParameters = autoclass('com.hedera.hashgraph.sdk.ContractFunctionParameters')
TokenRevokeKycTransaction = autoclass('com.hedera.hashgraph.sdk.TokenRevokeKycTransaction')
PrecheckStatusException = autoclass('com.hedera.hashgraph.sdk.PrecheckStatusException')
AccountBalanceQuery = autoclass('com.hedera.hashgraph.sdk.AccountBalanceQuery')
ScheduleCreateTransaction = autoclass('com.hedera.hashgraph.sdk.ScheduleCreateTransaction')
ExecutionState = autoclass('com.hedera.hashgraph.sdk.ExecutionState')
ProxyStaker = autoclass('com.hedera.hashgraph.sdk.ProxyStaker')
WithGetCost = autoclass('com.hedera.hashgraph.sdk.WithGetCost')
TopicInfo = autoclass('com.hedera.hashgraph.sdk.TopicInfo')
TransactionReceiptQuery = autoclass('com.hedera.hashgraph.sdk.TransactionReceiptQuery')
InstantConverter = autoclass('com.hedera.hashgraph.sdk.InstantConverter')
Network = autoclass('com.hedera.hashgraph.sdk.Network')
EntityIdHelper = autoclass('com.hedera.hashgraph.sdk.EntityIdHelper')
FeeSchedules = autoclass('com.hedera.hashgraph.sdk.FeeSchedules')
TokenInfoQuery = autoclass('com.hedera.hashgraph.sdk.TokenInfoQuery')
MaxQueryPaymentExceededException = autoclass('com.hedera.hashgraph.sdk.MaxQueryPaymentExceededException')
AccountUpdateTransaction = autoclass('com.hedera.hashgraph.sdk.AccountUpdateTransaction')
LiveHashAddTransaction = autoclass('com.hedera.hashgraph.sdk.LiveHashAddTransaction')
TransactionRecordQuery = autoclass('com.hedera.hashgraph.sdk.TransactionRecordQuery')
ThreadLocalSecureRandom = autoclass('com.hedera.hashgraph.sdk.ThreadLocalSecureRandom')
Executable = autoclass('com.hedera.hashgraph.sdk.Executable')
ContractInfo = autoclass('com.hedera.hashgraph.sdk.ContractInfo')
ContractByteCodeQuery = autoclass('com.hedera.hashgraph.sdk.ContractByteCodeQuery')
AccountId = autoclass('com.hedera.hashgraph.sdk.AccountId')
Node = autoclass('com.hedera.hashgraph.sdk.Node')
TransactionResponse = autoclass('com.hedera.hashgraph.sdk.TransactionResponse')
Query = autoclass('com.hedera.hashgraph.sdk.Query')
TokenFreezeTransaction = autoclass('com.hedera.hashgraph.sdk.TokenFreezeTransaction')
Pem = autoclass('com.hedera.hashgraph.sdk.Pem')
BadMnemonicReason = autoclass('com.hedera.hashgraph.sdk.BadMnemonicReason')
LiveHash = autoclass('com.hedera.hashgraph.sdk.LiveHash')
KeyList = autoclass('com.hedera.hashgraph.sdk.KeyList')
ContractId = autoclass('com.hedera.hashgraph.sdk.ContractId')
ContractExecuteTransaction = autoclass('com.hedera.hashgraph.sdk.ContractExecuteTransaction')
NetworkVersionInfoQuery = autoclass('com.hedera.hashgraph.sdk.NetworkVersionInfoQuery')
TopicDeleteTransaction = autoclass('com.hedera.hashgraph.sdk.TopicDeleteTransaction')
TopicId = autoclass('com.hedera.hashgraph.sdk.TopicId')
WithGetRecord = autoclass('com.hedera.hashgraph.sdk.WithGetRecord')
TokenGrantKycTransaction = autoclass('com.hedera.hashgraph.sdk.TokenGrantKycTransaction')
SystemUndeleteTransaction = autoclass('com.hedera.hashgraph.sdk.SystemUndeleteTransaction')
TokenCreateTransaction = autoclass('com.hedera.hashgraph.sdk.TokenCreateTransaction')
ScheduleId = autoclass('com.hedera.hashgraph.sdk.ScheduleId')
WithGetReceipt = autoclass('com.hedera.hashgraph.sdk.WithGetReceipt')
ChunkedTransaction = autoclass('com.hedera.hashgraph.sdk.ChunkedTransaction')
ContractFunctionSelector = autoclass('com.hedera.hashgraph.sdk.ContractFunctionSelector')
Crypto = autoclass('com.hedera.hashgraph.sdk.Crypto')
FileInfo = autoclass('com.hedera.hashgraph.sdk.FileInfo')
HederaPreCheckStatusException = autoclass('com.hedera.hashgraph.sdk.HederaPreCheckStatusException')
NetworkName = autoclass('com.hedera.hashgraph.sdk.NetworkName')
FileInfoQuery = autoclass('com.hedera.hashgraph.sdk.FileInfoQuery')
TokenDeleteTransaction = autoclass('com.hedera.hashgraph.sdk.TokenDeleteTransaction')
Keystore = autoclass('com.hedera.hashgraph.sdk.Keystore')
TransferTransaction = autoclass('com.hedera.hashgraph.sdk.TransferTransaction')
TopicInfoQuery = autoclass('com.hedera.hashgraph.sdk.TopicInfoQuery')
BadKeyException = autoclass('com.hedera.hashgraph.sdk.BadKeyException')
ContractInfoQuery = autoclass('com.hedera.hashgraph.sdk.ContractInfoQuery')
ScheduleInfoQuery = autoclass('com.hedera.hashgraph.sdk.ScheduleInfoQuery')
FileDeleteTransaction = autoclass('com.hedera.hashgraph.sdk.FileDeleteTransaction')
TopicMessageChunk = autoclass('com.hedera.hashgraph.sdk.TopicMessageChunk')
FileContentsQuery = autoclass('com.hedera.hashgraph.sdk.FileContentsQuery')
BadMnemonicException = autoclass('com.hedera.hashgraph.sdk.BadMnemonicException')
AccountBalance = autoclass('com.hedera.hashgraph.sdk.AccountBalance')
TransactionFeeSchedule = autoclass('com.hedera.hashgraph.sdk.TransactionFeeSchedule')
AccountCreateTransaction = autoclass('com.hedera.hashgraph.sdk.AccountCreateTransaction')
PublicKey = autoclass('com.hedera.hashgraph.sdk.PublicKey')
TokenId = autoclass('com.hedera.hashgraph.sdk.TokenId')
ReceiptStatusException = autoclass('com.hedera.hashgraph.sdk.ReceiptStatusException')
ContractCallQuery = autoclass('com.hedera.hashgraph.sdk.ContractCallQuery')
FileId = autoclass('com.hedera.hashgraph.sdk.FileId')
TokenBurnTransaction = autoclass('com.hedera.hashgraph.sdk.TokenBurnTransaction')
Client = autoclass('com.hedera.hashgraph.sdk.Client')
TokenWipeTransaction = autoclass('com.hedera.hashgraph.sdk.TokenWipeTransaction')
FileAppendTransaction = autoclass('com.hedera.hashgraph.sdk.FileAppendTransaction')
SystemDeleteTransaction = autoclass('com.hedera.hashgraph.sdk.SystemDeleteTransaction')
TransactionReceipt = autoclass('com.hedera.hashgraph.sdk.TransactionReceipt')
TokenAssociateTransaction = autoclass('com.hedera.hashgraph.sdk.TokenAssociateTransaction')
Transfer = autoclass('com.hedera.hashgraph.sdk.Transfer')
FeeData = autoclass('com.hedera.hashgraph.sdk.FeeData')
DurationConverter = autoclass('com.hedera.hashgraph.sdk.DurationConverter')
TransactionId = autoclass('com.hedera.hashgraph.sdk.TransactionId')
FutureConverter = autoclass('com.hedera.hashgraph.sdk.FutureConverter')
ExchangeRate = autoclass('com.hedera.hashgraph.sdk.ExchangeRate')
TransactionRecord = autoclass('com.hedera.hashgraph.sdk.TransactionRecord')
AccountStakersQuery = autoclass('com.hedera.hashgraph.sdk.AccountStakersQuery')
MirrorNetwork = autoclass('com.hedera.hashgraph.sdk.MirrorNetwork')
FileCreateTransaction = autoclass('com.hedera.hashgraph.sdk.FileCreateTransaction')
TokenRelationship = autoclass('com.hedera.hashgraph.sdk.TokenRelationship')
Transaction = autoclass('com.hedera.hashgraph.sdk.Transaction')
SubscriptionHandle = autoclass('com.hedera.hashgraph.sdk.SubscriptionHandle')
ContractFunctionResult = autoclass('com.hedera.hashgraph.sdk.ContractFunctionResult')
AccountInfo = autoclass('com.hedera.hashgraph.sdk.AccountInfo')
ContractUpdateTransaction = autoclass('com.hedera.hashgraph.sdk.ContractUpdateTransaction')
TopicUpdateTransaction = autoclass('com.hedera.hashgraph.sdk.TopicUpdateTransaction')
ContractLogInfo = autoclass('com.hedera.hashgraph.sdk.ContractLogInfo')
FeeComponents = autoclass('com.hedera.hashgraph.sdk.FeeComponents')
LiveHashDeleteTransaction = autoclass('com.hedera.hashgraph.sdk.LiveHashDeleteTransaction')
Status = autoclass('com.hedera.hashgraph.sdk.Status')
HbarUnit = autoclass('com.hedera.hashgraph.sdk.HbarUnit')
ScheduleSignTransaction = autoclass('com.hedera.hashgraph.sdk.ScheduleSignTransaction')
Mnemonic = autoclass('com.hedera.hashgraph.sdk.Mnemonic')
ContractCreateTransaction = autoclass('com.hedera.hashgraph.sdk.ContractCreateTransaction')
WithExecuteAll = autoclass('com.hedera.hashgraph.sdk.WithExecuteAll')
TokenInfo = autoclass('com.hedera.hashgraph.sdk.TokenInfo')
RequestType = autoclass('com.hedera.hashgraph.sdk.RequestType')
ManagedNode = autoclass('com.hedera.hashgraph.sdk.ManagedNode')
LiveHashQuery = autoclass('com.hedera.hashgraph.sdk.LiveHashQuery')
PrivateKey = autoclass('com.hedera.hashgraph.sdk.PrivateKey')
AccountRecordsQuery = autoclass('com.hedera.hashgraph.sdk.AccountRecordsQuery')
TopicMessageQuery = autoclass('com.hedera.hashgraph.sdk.TopicMessageQuery')
FreezeTransaction = autoclass('com.hedera.hashgraph.sdk.FreezeTransaction')
FileUpdateTransaction = autoclass('com.hedera.hashgraph.sdk.FileUpdateTransaction')
Hbar = autoclass('com.hedera.hashgraph.sdk.Hbar')
NetworkVersionInfo = autoclass('com.hedera.hashgraph.sdk.NetworkVersionInfo')
ScheduleDeleteTransaction = autoclass('com.hedera.hashgraph.sdk.ScheduleDeleteTransaction')
ParseAddressResult = autoclass('com.hedera.hashgraph.sdk.ParseAddressResult')
TopicMessage = autoclass('com.hedera.hashgraph.sdk.TopicMessage')
TopicCreateTransaction = autoclass('com.hedera.hashgraph.sdk.TopicCreateTransaction')
TokenUnfreezeTransaction = autoclass('com.hedera.hashgraph.sdk.TokenUnfreezeTransaction')
ScheduleInfo = autoclass('com.hedera.hashgraph.sdk.ScheduleInfo')
Key = autoclass('com.hedera.hashgraph.sdk.Key')
AccountDeleteTransaction = autoclass('com.hedera.hashgraph.sdk.AccountDeleteTransaction')
TopicMessageSubmitTransaction = autoclass('com.hedera.hashgraph.sdk.TopicMessageSubmitTransaction')


class PyConsumer(PythonJavaClass):
    __javainterfaces__ = ['java/util/function/Consumer']

    def __init__(self, fn):
        self.fn = fn

    @java_method('(Ljava/lang/Object;)V')
    def accept(self, msg):
        ts = msg.consensusTimestamp.toString()
        sn = msg.sequenceNumber
        contents = JString(msg.contents, JStandardCharsets.UTF_8).toString()
        self.fn(ts, sn, contents)
