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

namespace MyTelegram.Schema;

///<summary>
/// Notification settings.
/// See <a href="https://corefork.telegram.org/constructor/inputPeerNotifySettings" />
///</summary>
[TlObject(0xcacb6ae2)]
public sealed class TInputPeerNotifySettings : IInputPeerNotifySettings
{
    public uint ConstructorId => 0xcacb6ae2;
    ///<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 the text of the message shall be displayed in notification
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? ShowPreviews { get; set; }

    ///<summary>
    /// Peer was muted?
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? Silent { get; set; }

    ///<summary>
    /// Date until which all notifications shall be switched off
    ///</summary>
    public int? MuteUntil { get; set; }

    ///<summary>
    /// Identifier of an audio file to play for notifications.
    /// See <a href="https://corefork.telegram.org/type/NotificationSound" />
    ///</summary>
    public MyTelegram.Schema.INotificationSound? Sound { get; set; }

    ///<summary>
    /// Whether story notifications should be disabled.
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? StoriesMuted { get; set; }

    ///<summary>
    /// Whether the sender name should be displayed in story notifications.
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? StoriesHideSender { get; set; }

    ///<summary>
    /// Identifier of an audio file to play for story notifications.
    /// See <a href="https://corefork.telegram.org/type/NotificationSound" />
    ///</summary>
    public MyTelegram.Schema.INotificationSound? StoriesSound { get; set; }

    public void ComputeFlag()
    {
        if (ShowPreviews !=null) { Flags = Flags.SetBit(0); }
        if (Silent !=null) { Flags = Flags.SetBit(1); }
        if (/*MuteUntil != 0 && */MuteUntil.HasValue) { Flags = Flags.SetBit(2); }
        if (Sound != null) { Flags = Flags.SetBit(3); }
        if (StoriesMuted !=null) { Flags = Flags.SetBit(6); }
        if (StoriesHideSender !=null) { Flags = Flags.SetBit(7); }
        if (StoriesSound != null) { Flags = Flags.SetBit(8); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(ShowPreviews.Value); }
        if (Flags.IsBitSet(1)) { writer.Write(Silent.Value); }
        if (Flags.IsBitSet(2)) { writer.Write(MuteUntil.Value); }
        if (Flags.IsBitSet(3)) { writer.Write(Sound); }
        if (Flags.IsBitSet(6)) { writer.Write(StoriesMuted.Value); }
        if (Flags.IsBitSet(7)) { writer.Write(StoriesHideSender.Value); }
        if (Flags.IsBitSet(8)) { writer.Write(StoriesSound); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { ShowPreviews = buffer.Read(); }
        if (Flags.IsBitSet(1)) { Silent = buffer.Read(); }
        if (Flags.IsBitSet(2)) { MuteUntil = buffer.ReadInt32(); }
        if (Flags.IsBitSet(3)) { Sound = buffer.Read<MyTelegram.Schema.INotificationSound>(); }
        if (Flags.IsBitSet(6)) { StoriesMuted = buffer.Read(); }
        if (Flags.IsBitSet(7)) { StoriesHideSender = buffer.Read(); }
        if (Flags.IsBitSet(8)) { StoriesSound = buffer.Read<MyTelegram.Schema.INotificationSound>(); }
    }
}