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

namespace MyTelegram.Schema;

///<summary>
/// Reaction notification settings, see <a href="https://corefork.telegram.org/api/reactions#notifications-about-reactions">here »</a> for more info.
/// See <a href="https://corefork.telegram.org/constructor/reactionsNotifySettings" />
///</summary>
[TlObject(0x56e34970)]
public sealed class TReactionsNotifySettings : IReactionsNotifySettings
{
    public uint ConstructorId => 0x56e34970;
    ///<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>
    /// Message reaction notification settings, if not set completely disables notifications/updates about message reactions.
    /// See <a href="https://corefork.telegram.org/type/ReactionNotificationsFrom" />
    ///</summary>
    public MyTelegram.Schema.IReactionNotificationsFrom? MessagesNotifyFrom { get; set; }

    ///<summary>
    /// Story reaction notification settings, if not set completely disables notifications/updates about reactions to stories.
    /// See <a href="https://corefork.telegram.org/type/ReactionNotificationsFrom" />
    ///</summary>
    public MyTelegram.Schema.IReactionNotificationsFrom? StoriesNotifyFrom { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/ringtones">Notification sound for reactions »</a>
    /// See <a href="https://corefork.telegram.org/type/NotificationSound" />
    ///</summary>
    public MyTelegram.Schema.INotificationSound Sound { get; set; }

    ///<summary>
    /// If false, <a href="https://corefork.telegram.org/api/push-updates">push notifications »</a> about message/story reactions will only be of type <code>REACT_HIDDEN</code>/<code>REACT_STORY_HIDDEN</code>, without any information about the reacted-to story or the reaction itself.
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool ShowPreviews { get; set; }

    public void ComputeFlag()
    {
        if (MessagesNotifyFrom != null) { Flags = Flags.SetBit(0); }
        if (StoriesNotifyFrom != null) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(MessagesNotifyFrom); }
        if (Flags.IsBitSet(1)) { writer.Write(StoriesNotifyFrom); }
        writer.Write(Sound);
        writer.Write(ShowPreviews);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { MessagesNotifyFrom = buffer.Read<MyTelegram.Schema.IReactionNotificationsFrom>(); }
        if (Flags.IsBitSet(1)) { StoriesNotifyFrom = buffer.Read<MyTelegram.Schema.IReactionNotificationsFrom>(); }
        Sound = buffer.Read<MyTelegram.Schema.INotificationSound>();
        ShowPreviews = buffer.Read();
    }
}