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

namespace MyTelegram.Schema;

///<summary>
/// See <a href="https://corefork.telegram.org/constructor/messageActionSuggestedPostApproval" />
///</summary>
[TlObject(0xee7a1596)]
public sealed class TMessageActionSuggestedPostApproval : IMessageAction
{
    public uint ConstructorId => 0xee7a1596;
    public int Flags { get; set; }
    public bool Rejected { get; set; }
    public bool BalanceTooLow { get; set; }
    public string? RejectComment { get; set; }
    public int? ScheduleDate { get; set; }
    public MyTelegram.Schema.IStarsAmount? Price { get; set; }

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

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Rejected = true; }
        if (Flags.IsBitSet(1)) { BalanceTooLow = true; }
        if (Flags.IsBitSet(2)) { RejectComment = buffer.ReadString(); }
        if (Flags.IsBitSet(3)) { ScheduleDate = buffer.ReadInt32(); }
        if (Flags.IsBitSet(4)) { Price = buffer.Read<MyTelegram.Schema.IStarsAmount>(); }
    }
}