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

namespace MyTelegram.Schema;

///<summary>
/// Contains information about a single <a href="https://corefork.telegram.org/api/boost">boost slot »</a>.
/// See <a href="https://corefork.telegram.org/constructor/myBoost" />
///</summary>
[TlObject(0xc448415c)]
public sealed class TMyBoost : IMyBoost
{
    public uint ConstructorId => 0xc448415c;
    ///<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>
    /// <a href="https://corefork.telegram.org/api/boost">Boost slot ID »</a>
    ///</summary>
    public int Slot { get; set; }

    ///<summary>
    /// If set, indicates this slot is currently occupied, i.e. we are <a href="https://corefork.telegram.org/api/boost">boosting</a> this peer.  <br>Note that we can assign multiple boost slots to the same peer.
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer? Peer { get; set; }

    ///<summary>
    /// When (unixtime) we started boosting the <code>peer</code>, <code>0</code> otherwise.
    ///</summary>
    public int Date { get; set; }

    ///<summary>
    /// Indicates the (unixtime) expiration date of the boost in <code>peer</code> (<code>0</code> if <code>peer</code> is not set).
    ///</summary>
    public int Expires { get; set; }

    ///<summary>
    /// If <code>peer</code> is set, indicates the (unixtime) date after which this boost can be reassigned to another channel.
    ///</summary>
    public int? CooldownUntilDate { get; set; }

    public void ComputeFlag()
    {
        if (Peer != null) { Flags = Flags.SetBit(0); }
        if (/*CooldownUntilDate != 0 && */CooldownUntilDate.HasValue) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Slot);
        if (Flags.IsBitSet(0)) { writer.Write(Peer); }
        writer.Write(Date);
        writer.Write(Expires);
        if (Flags.IsBitSet(1)) { writer.Write(CooldownUntilDate.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Slot = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Peer = buffer.Read<MyTelegram.Schema.IPeer>(); }
        Date = buffer.ReadInt32();
        Expires = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { CooldownUntilDate = buffer.ReadInt32(); }
    }
}