import filters as f

from iota import TransactionHash, Address
from iota.commands import FilterCommand, RequestFilter, ResponseFilter
from iota.filters import Trytes

__all__ = [
    'GetNodeInfoCommand',
]


class GetNodeInfoCommand(FilterCommand):
    """
    Executes `getNodeInfo` command.

    See :py:meth:`iota.api.StrictIota.get_node_info`.
    """
    command = 'getNodeInfo'

    def get_request_filter(self):
        return GetNodeInfoRequestFilter()

    def get_response_filter(self):
        return GetNodeInfoResponseFilter()


class GetNodeInfoRequestFilter(RequestFilter):
    def __init__(self) -> None:
        # ``getNodeInfo`` does not accept any parameters.
        # Using a filter here just to enforce that the request is empty.
        super(GetNodeInfoRequestFilter, self).__init__({})


class GetNodeInfoResponseFilter(ResponseFilter):
    def __init__(self) -> None:
        super(GetNodeInfoResponseFilter, self).__init__({
            'coordinatorAddress':
                f.ByteString(encoding='ascii') | Trytes(Address),
            'latestMilestone':
                f.ByteString(encoding='ascii') | Trytes(TransactionHash),

            'latestSolidSubtangleMilestone':
                f.ByteString(encoding='ascii') | Trytes(TransactionHash),
        })

[((38, 16, 38, 46), 'filters.ByteString', 'f.ByteString', (), '', True, 'import filters as f\n'), ((38, 49, 38, 64), 'iota.filters.Trytes', 'Trytes', ({(38, 56, 38, 63): 'Address'}, {}), '(Address)', False, 'from iota.filters import Trytes\n'), ((40, 16, 40, 46), 'filters.ByteString', 'f.ByteString', (), '', True, 'import filters as f\n'), ((40, 49, 40, 72), 'iota.filters.Trytes', 'Trytes', ({(40, 56, 40, 71): 'TransactionHash'}, {}), '(TransactionHash)', False, 'from iota.filters import Trytes\n'), ((43, 16, 43, 46), 'filters.ByteString', 'f.ByteString', (), '', True, 'import filters as f\n'), ((43, 49, 43, 72), 'iota.filters.Trytes', 'Trytes', ({(43, 56, 43, 71): 'TransactionHash'}, {}), '(TransactionHash)', False, 'from iota.filters import Trytes\n')]