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

namespace MyTelegram.Schema;

///<summary>
/// A <a href="https://corefork.telegram.org/api/giveaways">giveaway</a> has ended.
/// See <a href="https://corefork.telegram.org/constructor/messageActionGiveawayResults" />
///</summary>
[TlObject(0x87e2f155)]
public sealed class TMessageActionGiveawayResults : IMessageAction
{
    public uint ConstructorId => 0x87e2f155;
    ///<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>
    /// If set, this is a <a href="https://corefork.telegram.org/api/stars#star-giveaways">Telegram Star giveaway</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Stars { get; set; }

    ///<summary>
    /// Number of winners in the giveaway
    ///</summary>
    public int WinnersCount { get; set; }

    ///<summary>
    /// Number of undistributed prizes
    ///</summary>
    public int UnclaimedCount { get; set; }

    public void ComputeFlag()
    {
        if (Stars) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(WinnersCount);
        writer.Write(UnclaimedCount);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Stars = true; }
        WinnersCount = buffer.ReadInt32();
        UnclaimedCount = buffer.ReadInt32();
    }
}