"""File generated by TLObjects' generator. All changes will be ERASED"""
from ...tl.tlobject import TLObject
from ...tl.tlobject import TLRequest
from typing import Optional, List, Union, TYPE_CHECKING
import os
import struct
from datetime import datetime
if TYPE_CHECKING:
    from ...tl.types import TypeInputAiComposeTone



class CreateToneRequest(TLRequest):
    CONSTRUCTOR_ID = 0x4aa83913
    SUBCLASS_OF_ID = 0xd476f30d

    def __init__(self, emoji_id: int, title: str, prompt: str, display_author: Optional[bool]=None):
        """
        :returns AiComposeTone: Instance of either AiComposeTone, AiComposeToneDefault.
        """
        self.emoji_id = emoji_id
        self.title = title
        self.prompt = prompt
        self.display_author = display_author

    def to_dict(self):
        return {
            '_': 'CreateToneRequest',
            'emoji_id': self.emoji_id,
            'title': self.title,
            'prompt': self.prompt,
            'display_author': self.display_author
        }

    def _bytes(self):
        return b''.join((
            b'\x139\xa8J',
            struct.pack('<I', (0 if self.display_author is None or self.display_author is False else 1)),
            struct.pack('<q', self.emoji_id),
            self.serialize_bytes(self.title),
            self.serialize_bytes(self.prompt),
        ))

    @classmethod
    def from_reader(cls, reader):
        flags = reader.read_int()

        _display_author = bool(flags & 1)
        _emoji_id = reader.read_long()
        _title = reader.tgread_string()
        _prompt = reader.tgread_string()
        return cls(emoji_id=_emoji_id, title=_title, prompt=_prompt, display_author=_display_author)


class DeleteToneRequest(TLRequest):
    CONSTRUCTOR_ID = 0xdd39316a
    SUBCLASS_OF_ID = 0xf5b399ac

    def __init__(self, tone: 'TypeInputAiComposeTone'):
        """
        :returns Bool: This type has no constructors.
        """
        self.tone = tone

    def to_dict(self):
        return {
            '_': 'DeleteToneRequest',
            'tone': self.tone.to_dict() if isinstance(self.tone, TLObject) else self.tone
        }

    def _bytes(self):
        return b''.join((
            b'j19\xdd',
            self.tone._bytes(),
        ))

    @classmethod
    def from_reader(cls, reader):
        _tone = reader.tgread_object()
        return cls(tone=_tone)


class GetToneRequest(TLRequest):
    CONSTRUCTOR_ID = 0xb2e8ba03
    SUBCLASS_OF_ID = 0xf25ffed9

    def __init__(self, tone: 'TypeInputAiComposeTone'):
        """
        :returns aicompose.Tones: Instance of either TonesNotModified, Tones.
        """
        self.tone = tone

    def to_dict(self):
        return {
            '_': 'GetToneRequest',
            'tone': self.tone.to_dict() if isinstance(self.tone, TLObject) else self.tone
        }

    def _bytes(self):
        return b''.join((
            b'\x03\xba\xe8\xb2',
            self.tone._bytes(),
        ))

    @classmethod
    def from_reader(cls, reader):
        _tone = reader.tgread_object()
        return cls(tone=_tone)


class GetToneExampleRequest(TLRequest):
    CONSTRUCTOR_ID = 0xd1b4ab14
    SUBCLASS_OF_ID = 0x8c2493d5

    def __init__(self, tone: 'TypeInputAiComposeTone', num: int):
        """
        :returns AiComposeToneExample: Instance of AiComposeToneExample.
        """
        self.tone = tone
        self.num = num

    def to_dict(self):
        return {
            '_': 'GetToneExampleRequest',
            'tone': self.tone.to_dict() if isinstance(self.tone, TLObject) else self.tone,
            'num': self.num
        }

    def _bytes(self):
        return b''.join((
            b'\x14\xab\xb4\xd1',
            self.tone._bytes(),
            struct.pack('<i', self.num),
        ))

    @classmethod
    def from_reader(cls, reader):
        _tone = reader.tgread_object()
        _num = reader.read_int()
        return cls(tone=_tone, num=_num)


class GetTonesRequest(TLRequest):
    CONSTRUCTOR_ID = 0xabd59201
    SUBCLASS_OF_ID = 0xf25ffed9

    def __init__(self, hash: int):
        """
        :returns aicompose.Tones: Instance of either TonesNotModified, Tones.
        """
        self.hash = hash

    def to_dict(self):
        return {
            '_': 'GetTonesRequest',
            'hash': self.hash
        }

    def _bytes(self):
        return b''.join((
            b'\x01\x92\xd5\xab',
            struct.pack('<q', self.hash),
        ))

    @classmethod
    def from_reader(cls, reader):
        _hash = reader.read_long()
        return cls(hash=_hash)


class SaveToneRequest(TLRequest):
    CONSTRUCTOR_ID = 0x1782cbb1
    SUBCLASS_OF_ID = 0xf5b399ac

    def __init__(self, tone: 'TypeInputAiComposeTone', unsave: bool):
        """
        :returns Bool: This type has no constructors.
        """
        self.tone = tone
        self.unsave = unsave

    def to_dict(self):
        return {
            '_': 'SaveToneRequest',
            'tone': self.tone.to_dict() if isinstance(self.tone, TLObject) else self.tone,
            'unsave': self.unsave
        }

    def _bytes(self):
        return b''.join((
            b'\xb1\xcb\x82\x17',
            self.tone._bytes(),
            b'\xb5ur\x99' if self.unsave else b'7\x97y\xbc',
        ))

    @classmethod
    def from_reader(cls, reader):
        _tone = reader.tgread_object()
        _unsave = reader.tgread_bool()
        return cls(tone=_tone, unsave=_unsave)


class UpdateToneRequest(TLRequest):
    CONSTRUCTOR_ID = 0x903bcf59
    SUBCLASS_OF_ID = 0xd476f30d

    def __init__(self, tone: 'TypeInputAiComposeTone', display_author: Optional[bool]=None, emoji_id: Optional[int]=None, title: Optional[str]=None, prompt: Optional[str]=None):
        """
        :returns AiComposeTone: Instance of either AiComposeTone, AiComposeToneDefault.
        """
        self.tone = tone
        self.display_author = display_author
        self.emoji_id = emoji_id
        self.title = title
        self.prompt = prompt

    def to_dict(self):
        return {
            '_': 'UpdateToneRequest',
            'tone': self.tone.to_dict() if isinstance(self.tone, TLObject) else self.tone,
            'display_author': self.display_author,
            'emoji_id': self.emoji_id,
            'title': self.title,
            'prompt': self.prompt
        }

    def _bytes(self):
        return b''.join((
            b'Y\xcf;\x90',
            struct.pack('<I', (0 if self.display_author is None else 1) | (0 if self.emoji_id is None or self.emoji_id is False else 2) | (0 if self.title is None or self.title is False else 4) | (0 if self.prompt is None or self.prompt is False else 8)),
            self.tone._bytes(),
            b'' if self.display_author is None else (b'\xb5ur\x99' if self.display_author else b'7\x97y\xbc'),
            b'' if self.emoji_id is None or self.emoji_id is False else (struct.pack('<q', self.emoji_id)),
            b'' if self.title is None or self.title is False else (self.serialize_bytes(self.title)),
            b'' if self.prompt is None or self.prompt is False else (self.serialize_bytes(self.prompt)),
        ))

    @classmethod
    def from_reader(cls, reader):
        flags = reader.read_int()

        _tone = reader.tgread_object()
        if flags & 1:
            _display_author = reader.tgread_bool()
        else:
            _display_author = None
        if flags & 2:
            _emoji_id = reader.read_long()
        else:
            _emoji_id = None
        if flags & 4:
            _title = reader.tgread_string()
        else:
            _title = None
        if flags & 8:
            _prompt = reader.tgread_string()
        else:
            _prompt = None
        return cls(tone=_tone, display_author=_display_author, emoji_id=_emoji_id, title=_title, prompt=_prompt)

