"""File auto-generated by tglib TL generator. Do not edit manually."""
from ..tlobject import TLObject
from typing import Optional, List, Union
import os
import struct
from datetime import datetime


class CollectibleInfo(TLObject):
    """TL type: fragment.collectibleInfo"""
    CONSTRUCTOR_ID = 0x6ebdff91
    SUBCLASS_OF_ID = 0xd4ea5790

    def __init__(self, purchase_date: Optional[datetime], currency: str, amount: int, crypto_currency: str, crypto_amount: int, url: str):
        self.purchase_date = purchase_date
        self.currency = currency
        self.amount = amount
        self.crypto_currency = crypto_currency
        self.crypto_amount = crypto_amount
        self.url = url

    def to_dict(self):
        return {
            '_': 'CollectibleInfo',
            'purchase_date': self.purchase_date,
            'currency': self.currency,
            'amount': self.amount,
            'crypto_currency': self.crypto_currency,
            'crypto_amount': self.crypto_amount,
            'url': self.url,
        }

    def _bytes(self) -> bytes:
        import io
        buf = io.BytesIO()
        buf.write(struct.pack('<I', self.CONSTRUCTOR_ID))
        buf.write(struct.pack('<i', self.purchase_date))
        buf.write(TLObject.serialize_bytes(self.currency))
        buf.write(struct.pack('<q', self.amount))
        buf.write(TLObject.serialize_bytes(self.crypto_currency))
        buf.write(struct.pack('<q', self.crypto_amount))
        buf.write(TLObject.serialize_bytes(self.url))
        return buf.getvalue()

    @classmethod
    def from_reader(cls, reader):
        _args = {}
        _val_purchase_date = reader.read_int()
        _args['purchase_date'] = _val_purchase_date
        _val_currency = reader.tgread_string()
        _args['currency'] = _val_currency
        _val_amount = reader.read_long()
        _args['amount'] = _val_amount
        _val_crypto_currency = reader.tgread_string()
        _args['crypto_currency'] = _val_crypto_currency
        _val_crypto_amount = reader.read_long()
        _args['crypto_amount'] = _val_crypto_amount
        _val_url = reader.tgread_string()
        _args['url'] = _val_url
        return cls(**_args)

