# AUTOGENERATED – DO NOT EDIT
from __future__ import annotations
import json
import http.client
from typing import Any, Dict, List, Optional, Union

from .transactions import *
from .signatures import *
from .types import *
from .enums import *

class JsonRpcClient:
    """JSON-RPC client for Accumulate API."""

    def __init__(self, host: str):
        """
        Initialize the client.

        Args:
            host: Host and port (e.g., "localhost:26660" or "testnet.accumulatenetwork.io")
        """
        self.host = host

    def call(self, method: str, params: Dict[str, Any]) -> Any:
        """
        Make a JSON-RPC call to the Accumulate API.

        Args:
            method: The RPC method name
            params: Parameters for the method

        Returns:
            The result from the API call

        Raises:
            RuntimeError: If the API returns an error
        """
        conn = http.client.HTTPConnection(self.host)
        payload = json.dumps({
            "jsonrpc": "2.0",
            "id": 1,
            "method": method,
            "params": params
        })

        conn.request(
            "POST",
            "/v3",
            body=payload,
            headers={"Content-Type": "application/json"}
        )

        res = conn.getresponse()
        raw = res.read().decode("utf-8")
        conn.close()

        data = json.loads(raw)
        if "error" in data:
            raise RuntimeError(f"API Error: {data['error']}")

        return data.get("result")

    def Status(self) -> StatusResponse:
        """queries the status of the node

        RPC method: Status
        """
        params = {
        }
        return self.call("Status", params)

    def Version(self) -> ChainQueryResponse:
        """queries the software version of the node

        RPC method: Version
        """
        params = {
        }
        return self.call("Version", params)

    def Describe(self) -> DescriptionResponse:
        """queries the basic configuration of the node

        RPC method: Describe
        """
        params = {
        }
        return self.call("Describe", params)

    def Metrics(self) -> ChainQueryResponse:
        """queries network metrics, such as transactions per second

        RPC method: Metrics
        """
        params = {
        }
        return self.call("Metrics", params)

    def Faucet(self) -> TxResponse:
        """requests tokens from the ACME faucet

        RPC method: Faucet
        """
        params = {
        }
        return self.call("Faucet", params)

    def Query(self) -> Union[ChainQueryResponse, TransactionQueryResponse, MultiResponse]:
        """queries an account or account chain by URL

        RPC method: Query
        """
        params = {
        }
        return self.call("Query", params)

    def QueryDirectory(self) -> MultiResponse:
        """queries the directory entries of an account

        RPC method: QueryDirectory
        """
        params = {
        }
        return self.call("QueryDirectory", params)

    def QueryTx(self) -> TransactionQueryResponse:
        """queries a transaction by ID

        RPC method: QueryTx
        """
        params = {
        }
        return self.call("QueryTx", params)

    def QueryTxLocal(self) -> TransactionQueryResponse:
        """queries a transaction by ID

        RPC method: QueryTxLocal
        """
        params = {
        }
        return self.call("QueryTxLocal", params)

    def QueryTxHistory(self) -> MultiResponse:
        """queries an account's transaction history

        RPC method: QueryTxHistory
        """
        params = {
        }
        return self.call("QueryTxHistory", params)

    def QueryData(self) -> ChainQueryResponse:
        """queries an entry on an account's data chain

        RPC method: QueryData
        """
        params = {
        }
        return self.call("QueryData", params)

    def QueryDataSet(self) -> MultiResponse:
        """queries a range of entries on an account's data chain

        RPC method: QueryDataSet
        """
        params = {
        }
        return self.call("QueryDataSet", params)

    def QueryKeyPageIndex(self) -> ChainQueryResponse:
        """queries the location of a key within an account's key book(s)

        RPC method: QueryKeyPageIndex
        """
        params = {
        }
        return self.call("QueryKeyPageIndex", params)

    def QueryMinorBlocks(self) -> MultiResponse:
        """queries an account's minor blocks

        RPC method: QueryMinorBlocks
        """
        params = {
        }
        return self.call("QueryMinorBlocks", params)

    def QueryMajorBlocks(self) -> MultiResponse:
        """queries an account's major blocks

        RPC method: QueryMajorBlocks
        """
        params = {
        }
        return self.call("QueryMajorBlocks", params)

    def QuerySynth(self) -> TransactionQueryResponse:
        """

        RPC method: QuerySynth
        """
        params = {
        }
        return self.call("QuerySynth", params)

    def Execute(self) -> TxResponse:
        """submits a transaction

        RPC method: Execute
        """
        params = {
        }
        return self.call("Execute", params)

    def ExecuteDirect(self) -> TxResponse:
        """submits a transaction

        RPC method: ExecuteDirect
        """
        params = {
        }
        return self.call("ExecuteDirect", params)

    def ExecuteLocal(self) -> TxResponse:
        """submits a transaction without routing it. INTENDED FOR INTERNAL USE ONLY

        RPC method: ExecuteLocal
        """
        params = {
        }
        return self.call("ExecuteLocal", params)

    def ExecuteCreateAdi(self) -> Any:
        """submits a CreateIdentity transaction

        RPC method: ExecuteCreateAdi
        """
        params = {
        }
        return self.call("ExecuteCreateAdi", params)

    def ExecuteCreateIdentity(self) -> Any:
        """submits a CreateIdentity transaction

        RPC method: ExecuteCreateIdentity
        """
        params = {
        }
        return self.call("ExecuteCreateIdentity", params)

    def ExecuteCreateDataAccount(self) -> Any:
        """submits a CreateDataAccount transaction

        RPC method: ExecuteCreateDataAccount
        """
        params = {
        }
        return self.call("ExecuteCreateDataAccount", params)

    def ExecuteCreateKeyBook(self) -> Any:
        """submits a CreateKeyBook transaction

        RPC method: ExecuteCreateKeyBook
        """
        params = {
        }
        return self.call("ExecuteCreateKeyBook", params)

    def ExecuteCreateKeyPage(self) -> Any:
        """submits a CreateKeyPage transaction

        RPC method: ExecuteCreateKeyPage
        """
        params = {
        }
        return self.call("ExecuteCreateKeyPage", params)

    def ExecuteCreateToken(self) -> Any:
        """submits a CreateToken transaction

        RPC method: ExecuteCreateToken
        """
        params = {
        }
        return self.call("ExecuteCreateToken", params)

    def ExecuteCreateTokenAccount(self) -> Any:
        """submits a CreateTokenAccount transaction

        RPC method: ExecuteCreateTokenAccount
        """
        params = {
        }
        return self.call("ExecuteCreateTokenAccount", params)

    def ExecuteSendTokens(self) -> Any:
        """submits a SendTokens transaction

        RPC method: ExecuteSendTokens
        """
        params = {
        }
        return self.call("ExecuteSendTokens", params)

    def ExecuteAddCredits(self) -> Any:
        """submits an AddCredits transaction

        RPC method: ExecuteAddCredits
        """
        params = {
        }
        return self.call("ExecuteAddCredits", params)

    def ExecuteUpdateKeyPage(self) -> Any:
        """submits an UpdateKeyPage transaction

        RPC method: ExecuteUpdateKeyPage
        """
        params = {
        }
        return self.call("ExecuteUpdateKeyPage", params)

    def ExecuteUpdateKey(self) -> Any:
        """submits an UpdateKey transaction

        RPC method: ExecuteUpdateKey
        """
        params = {
        }
        return self.call("ExecuteUpdateKey", params)

    def ExecuteWriteData(self) -> Any:
        """submits a WriteData transaction

        RPC method: ExecuteWriteData
        """
        params = {
        }
        return self.call("ExecuteWriteData", params)

    def ExecuteIssueTokens(self) -> Any:
        """submits an IssueTokens transaction

        RPC method: ExecuteIssueTokens
        """
        params = {
        }
        return self.call("ExecuteIssueTokens", params)

    def ExecuteWriteDataTo(self) -> Any:
        """submits a WriteDataTo transaction

        RPC method: ExecuteWriteDataTo
        """
        params = {
        }
        return self.call("ExecuteWriteDataTo", params)

    def ExecuteBurnTokens(self) -> Any:
        """submits a BurnTokens transaction

        RPC method: ExecuteBurnTokens
        """
        params = {
        }
        return self.call("ExecuteBurnTokens", params)

    def ExecuteUpdateAccountAuth(self) -> Any:
        """submits an UpdateAccountAuth transaction

        RPC method: ExecuteUpdateAccountAuth
        """
        params = {
        }
        return self.call("ExecuteUpdateAccountAuth", params)


__all__ = ["JsonRpcClient"]