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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Informs the server that the user has interacted with a sponsored message in <a href="https://corefork.telegram.org/api/sponsored-messages#clicking-on-sponsored-messages">one of the ways listed here »</a>.
/// See <a href="https://corefork.telegram.org/method/messages.clickSponsoredMessage" />
///</summary>
[TlObject(0x8235057e)]
public sealed class RequestClickSponsoredMessage : IRequest<IBool>
{
    public uint ConstructorId => 0x8235057e;
    ///<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>
    /// The user clicked on the media
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Media { get; set; }

    ///<summary>
    /// The user expanded the video to full screen, and then clicked on it.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Fullscreen { get; set; }

    ///<summary>
    /// The ad's unique ID.
    ///</summary>
    public ReadOnlyMemory<byte> RandomId { get; set; }

    public void ComputeFlag()
    {
        if (Media) { Flags = Flags.SetBit(0); }
        if (Fullscreen) { Flags = Flags.SetBit(1); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Media = true; }
        if (Flags.IsBitSet(1)) { Fullscreen = true; }
        RandomId = buffer.ReadBytes();
    }
}
