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

namespace MyTelegram.Schema;

///<summary>
/// The results of a poll have changed
/// See <a href="https://corefork.telegram.org/constructor/updateMessagePoll" />
///</summary>
[TlObject(0xaca1657b)]
public sealed class TUpdateMessagePoll : IUpdate
{
    public uint ConstructorId => 0xaca1657b;
    ///<summary>
    /// Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a>
    ///</summary>
    public int Flags { get; set; }

    ///<summary>
    /// Poll ID
    ///</summary>
    public long PollId { get; set; }

    ///<summary>
    /// If the server knows the client hasn't cached this poll yet, the poll itself
    /// See <a href="https://corefork.telegram.org/type/Poll" />
    ///</summary>
    public MyTelegram.Schema.IPoll? Poll { get; set; }

    ///<summary>
    /// New poll results
    /// See <a href="https://corefork.telegram.org/type/PollResults" />
    ///</summary>
    public MyTelegram.Schema.IPollResults Results { get; set; }

    public void ComputeFlag()
    {
        if (Poll != null) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(PollId);
        if (Flags.IsBitSet(0)) { writer.Write(Poll); }
        writer.Write(Results);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        PollId = buffer.ReadInt64();
        if (Flags.IsBitSet(0)) { Poll = buffer.Read<MyTelegram.Schema.IPoll>(); }
        Results = buffer.Read<MyTelegram.Schema.IPollResults>();
    }
}