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

namespace MyTelegram.Schema.Account;

///<summary>
/// See <a href="https://corefork.telegram.org/method/account.toggleNoPaidMessagesException" />
///</summary>
[TlObject(0xfe2eda76)]
public sealed class RequestToggleNoPaidMessagesException : IRequest<IBool>
{
    public uint ConstructorId => 0xfe2eda76;
    public int Flags { get; set; }
    public bool RefundCharged { get; set; }
    public bool RequirePayment { get; set; }
    public MyTelegram.Schema.IInputPeer? ParentPeer { get; set; }
    public MyTelegram.Schema.IInputUser UserId { get; set; }

    public void ComputeFlag()
    {
        if (RefundCharged) { Flags = Flags.SetBit(0); }
        if (RequirePayment) { Flags = Flags.SetBit(2); }
        if (ParentPeer != null) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(1)) { writer.Write(ParentPeer); }
        writer.Write(UserId);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { RefundCharged = true; }
        if (Flags.IsBitSet(2)) { RequirePayment = true; }
        if (Flags.IsBitSet(1)) { ParentPeer = buffer.Read<MyTelegram.Schema.IInputPeer>(); }
        UserId = buffer.Read<MyTelegram.Schema.IInputUser>();
    }
}
