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

namespace MyTelegram.Schema.Messages;

///<summary>
/// See <a href="https://corefork.telegram.org/method/messages.toggleSuggestedPostApproval" />
///</summary>
[TlObject(0x8107455c)]
public sealed class RequestToggleSuggestedPostApproval : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0x8107455c;
    public int Flags { get; set; }
    public bool Reject { get; set; }
    public MyTelegram.Schema.IInputPeer Peer { get; set; }
    public int MsgId { get; set; }
    public int? ScheduleDate { get; set; }
    public string? RejectComment { get; set; }

    public void ComputeFlag()
    {
        if (Reject) { Flags = Flags.SetBit(1); }
        if (/*ScheduleDate != 0 && */ScheduleDate.HasValue) { Flags = Flags.SetBit(0); }
        if (RejectComment != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(MsgId);
        if (Flags.IsBitSet(0)) { writer.Write(ScheduleDate.Value); }
        if (Flags.IsBitSet(2)) { writer.Write(RejectComment); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { Reject = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        MsgId = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { ScheduleDate = buffer.ReadInt32(); }
        if (Flags.IsBitSet(2)) { RejectComment = buffer.ReadString(); }
    }
}
