from ....tl.tlobject import TLObject
from ....utils import get_input_channel, get_input_user


class GetAdminLogRequest(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    channels.getAdminLog#33ddf480 flags:# channel:InputChannel q:string events_filter:flags.0?ChannelAdminLogEventsFilter admins:flags.1?Vector<InputUser> max_id:long min_id:long limit:int = channels.AdminLogResults"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0x33ddf480
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x51f076bc

    def __init__(self, channel, q, max_id, min_id, limit, events_filter=None, admins=None):
        """
        :param channel: Telegram type: "InputChannel".
        :param q: Telegram type: "string".
        :param events_filter: Telegram type: "ChannelAdminLogEventsFilter".
        :param admins: Telegram type: "InputUser". Must be a list.
        :param max_id: Telegram type: "long".
        :param min_id: Telegram type: "long".
        :param limit: Telegram type: "int".

        :returns channels.AdminLogResults: Instance of AdminLogResults.
        """
        super().__init__()
        self.result = None
        self.content_related = True

        self.channel = get_input_channel(channel)
        self.q = q
        self.events_filter = events_filter
        self.admins = [get_input_user(_x) for _x in admins]
        self.max_id = max_id
        self.min_id = min_id
        self.limit = limit

    def to_dict(self):
        return {
            'channel': None if self.channel is None else self.channel.to_dict(),
            'q': self.q,
            'events_filter': None if self.events_filter is None else self.events_filter.to_dict(),
            'admins': [] if self.admins is None else [None if x is None else x.to_dict() for x in self.admins],
            'max_id': self.max_id,
            'min_id': self.min_id,
            'limit': self.limit,
        }

    def on_send(self, writer):
        writer.write_int(GetAdminLogRequest.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.events_filter else 0
        flags |= (1 << 1) if self.admins else 0
        writer.write_int(flags)

        self.channel.on_send(writer)
        writer.tgwrite_string(self.q)
        if self.events_filter:
            self.events_filter.on_send(writer)

        if self.admins:
            writer.write_int(0x1cb5c415, signed=False)  # Vector's constructor ID
            writer.write_int(len(self.admins))
            for _x in self.admins:
                if _x:
                    _x.on_send(writer)

        writer.write_long(self.max_id)
        writer.write_long(self.min_id)
        writer.write_int(self.limit)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return GetAdminLogRequest(None, None, None, None, None, None, None)

    def on_response(self, reader):
        self.result = reader.tgread_object()

    def __repr__(self):
        return 'channels.getAdminLog#33ddf480 flags:# channel:InputChannel q:string events_filter:flags.0?ChannelAdminLogEventsFilter admins:flags.1?Vector<InputUser> max_id:long min_id:long limit:int = channels.AdminLogResults'

    def __str__(self):
        return TLObject.pretty_format(self)

    def stringify(self):
        return TLObject.pretty_format(self, indent=0)
