// <auto-generated/>
// ReSharper disable All

namespace MyTelegram.Schema;

///<summary>
/// Encrypted message.
/// See <a href="https://corefork.telegram.org/constructor/encryptedMessage" />
///</summary>
[TlObject(0xed18c118)]
public sealed class TEncryptedMessage : IEncryptedMessage
{
    public uint ConstructorId => 0xed18c118;
    ///<summary>
    /// Random message ID, assigned by the author of message
    ///</summary>
    public long RandomId { get; set; }

    ///<summary>
    /// ID of encrypted chat
    ///</summary>
    public int ChatId { get; set; }

    ///<summary>
    /// Date of sending
    ///</summary>
    public int Date { get; set; }

    ///<summary>
    /// TL-serialization of <a href="https://corefork.telegram.org/type/DecryptedMessage">DecryptedMessage</a> type, encrypted with the key created at chat initialization
    ///</summary>
    public ReadOnlyMemory<byte> Bytes { get; set; }

    ///<summary>
    /// Attached encrypted file
    /// See <a href="https://corefork.telegram.org/type/EncryptedFile" />
    ///</summary>
    public MyTelegram.Schema.IEncryptedFile File { get; set; }

    public void ComputeFlag()
    {

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(RandomId);
        writer.Write(ChatId);
        writer.Write(Date);
        writer.Write(Bytes);
        writer.Write(File);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        RandomId = buffer.ReadInt64();
        ChatId = buffer.ReadInt32();
        Date = buffer.ReadInt32();
        Bytes = buffer.ReadBytes();
        File = buffer.Read<MyTelegram.Schema.IEncryptedFile>();
    }
}