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, 'filters.ByteString', 'f.ByteString', True, 'import filters as f\n'), (38, 'iota.filters.Trytes', 'Trytes', False, 'from iota.filters import Trytes\n'), (40, 'filters.ByteString', 'f.ByteString', True, 'import filters as f\n'), (40, 'iota.filters.Trytes', 'Trytes', False, 'from iota.filters import Trytes\n'), (43, 'filters.ByteString', 'f.ByteString', True, 'import filters as f\n'), (43, 'iota.filters.Trytes', 'Trytes', False, 'from iota.filters import Trytes\n')]