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

namespace MyTelegram.Schema.Bots;

///<summary>
/// See <a href="https://corefork.telegram.org/method/bots.setCustomVerification" />
///</summary>
[TlObject(0x8b89dfbd)]
public sealed class RequestSetCustomVerification : IRequest<IBool>
{
    public uint ConstructorId => 0x8b89dfbd;
    public int Flags { get; set; }
    public bool Enabled { get; set; }
    public MyTelegram.Schema.IInputUser? Bot { get; set; }
    public MyTelegram.Schema.IInputPeer Peer { get; set; }
    public string? CustomDescription { get; set; }

    public void ComputeFlag()
    {
        if (Enabled) { Flags = Flags.SetBit(1); }
        if (Bot != null) { Flags = Flags.SetBit(0); }
        if (CustomDescription != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(Bot); }
        writer.Write(Peer);
        if (Flags.IsBitSet(2)) { writer.Write(CustomDescription); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { Enabled = true; }
        if (Flags.IsBitSet(0)) { Bot = buffer.Read<MyTelegram.Schema.IInputUser>(); }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        if (Flags.IsBitSet(2)) { CustomDescription = buffer.ReadString(); }
    }
}
