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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Use this method to set the score of the specified user in a game sent as a normal message (bots only).
/// <para>Possible errors</para>
/// Code Type Description
/// 400 BOT_SCORE_NOT_MODIFIED The score wasn't modified.
/// 400 MESSAGE_ID_INVALID The provided message id is invalid.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// 400 SCORE_INVALID The specified game score is invalid.
/// 400 USER_BOT_REQUIRED This method can only be called by a bot.
/// See <a href="https://corefork.telegram.org/method/messages.setGameScore" />
///</summary>
[TlObject(0x8ef8ecc0)]
public sealed class RequestSetGameScore : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0x8ef8ecc0;
    ///<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>
    /// Set this flag if the game message should be automatically edited to include the current scoreboard
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool EditMessage { get; set; }

    ///<summary>
    /// Set this flag if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Force { get; set; }

    ///<summary>
    /// Unique identifier of target chat
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// Identifier of the sent message
    ///</summary>
    public int Id { get; set; }

    ///<summary>
    /// User identifier
    /// See <a href="https://corefork.telegram.org/type/InputUser" />
    ///</summary>
    public MyTelegram.Schema.IInputUser UserId { get; set; }

    ///<summary>
    /// New score
    ///</summary>
    public int Score { get; set; }

    public void ComputeFlag()
    {
        if (EditMessage) { Flags = Flags.SetBit(0); }
        if (Force) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(Id);
        writer.Write(UserId);
        writer.Write(Score);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { EditMessage = true; }
        if (Flags.IsBitSet(1)) { Force = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        Id = buffer.ReadInt32();
        UserId = buffer.Read<MyTelegram.Schema.IInputUser>();
        Score = buffer.ReadInt32();
    }
}
