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

namespace MyTelegram.Schema;

///<summary>
/// The <a href="https://corefork.telegram.org/api/wallpapers">wallpaper »</a> of the current chat was changed.
/// See <a href="https://corefork.telegram.org/constructor/messageActionSetChatWallPaper" />
///</summary>
[TlObject(0x5060a3f4)]
public sealed class TMessageActionSetChatWallPaper : IMessageAction
{
    public uint ConstructorId => 0x5060a3f4;
    ///<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, indicates the user applied a <a href="https://corefork.telegram.org/api/wallpapers">wallpaper »</a> previously sent by the other user in a <a href="https://corefork.telegram.org/constructor/messageActionSetChatWallPaper">messageActionSetChatWallPaper</a> message.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Same { get; set; }

    ///<summary>
    /// If set, indicates the wallpaper was forcefully applied for both sides, without explicit confirmation from the other side. <br>If the message is incoming, and we did not like the new wallpaper the other user has chosen for us, we can re-set our previous wallpaper just on our side, by invoking <a href="https://corefork.telegram.org/method/messages.setChatWallPaper">messages.setChatWallPaper</a>, providing only the <code>revert</code> flag (and obviously the <code>peer</code> parameter).
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ForBoth { get; set; }

    ///<summary>
    /// New <a href="https://corefork.telegram.org/api/wallpapers">wallpaper</a>
    /// See <a href="https://corefork.telegram.org/type/WallPaper" />
    ///</summary>
    public MyTelegram.Schema.IWallPaper Wallpaper { get; set; }

    public void ComputeFlag()
    {
        if (Same) { Flags = Flags.SetBit(0); }
        if (ForBoth) { Flags = Flags.SetBit(1); }

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Same = true; }
        if (Flags.IsBitSet(1)) { ForBoth = true; }
        Wallpaper = buffer.Read<MyTelegram.Schema.IWallPaper>();
    }
}