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

namespace MyTelegram.Schema.Account;

///<summary>
/// Sensitive content settings
/// See <a href="https://corefork.telegram.org/constructor/account.contentSettings" />
///</summary>
[TlObject(0x57e28221)]
public sealed class TContentSettings : IContentSettings
{
    public uint ConstructorId => 0x57e28221;
    ///<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>
    /// Whether viewing of sensitive (NSFW) content is enabled
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SensitiveEnabled { get; set; }

    ///<summary>
    /// Whether the current client can change the sensitive content settings to view NSFW content
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SensitiveCanChange { get; set; }

    public void ComputeFlag()
    {
        if (SensitiveEnabled) { Flags = Flags.SetBit(0); }
        if (SensitiveCanChange) { Flags = Flags.SetBit(1); }
    }

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

    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { SensitiveEnabled = true; }
        if (Flags.IsBitSet(1)) { SensitiveCanChange = true; }
    }
}