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

namespace MyTelegram.Schema;

///<summary>
/// Choose a user.
/// See <a href="https://corefork.telegram.org/constructor/requestPeerTypeUser" />
///</summary>
[TlObject(0x5f3b8a00)]
public sealed class TRequestPeerTypeUser : IRequestPeerType
{
    public uint ConstructorId => 0x5f3b8a00;
    ///<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>
    /// Whether to allow choosing only bots.
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? Bot { get; set; }

    ///<summary>
    /// Whether to allow choosing only <a href="https://corefork.telegram.org/api/premium">Premium</a> users.
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? Premium { get; set; }

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

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(Bot.Value); }
        if (Flags.IsBitSet(1)) { writer.Write(Premium.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Bot = buffer.Read(); }
        if (Flags.IsBitSet(1)) { Premium = buffer.Read(); }
    }
}