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

namespace MyTelegram.Schema;

///<summary>
/// See <a href="https://corefork.telegram.org/constructor/suggestedPost" />
///</summary>
[TlObject(0xe8e37e5)]
public sealed class TSuggestedPost : ISuggestedPost
{
    public uint ConstructorId => 0xe8e37e5;
    public int Flags { get; set; }
    public bool Accepted { get; set; }
    public bool Rejected { get; set; }
    public MyTelegram.Schema.IStarsAmount? Price { get; set; }
    public int? ScheduleDate { get; set; }

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

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

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