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

namespace MyTelegram.Schema.Account;

///<summary>
/// Initialize a <a href="https://corefork.telegram.org/api/takeout">takeout session, see here » for more info</a>.
/// <para>Possible errors</para>
/// Code Type Description
/// 420 TAKEOUT_INIT_DELAY_%d Sorry, for security reasons, you will be able to begin downloading your data in %d seconds. We have notified all your devices about the export request to make sure it's authorized and to give you time to react if it's not.
/// See <a href="https://corefork.telegram.org/method/account.initTakeoutSession" />
///</summary>
[TlObject(0x8ef3eab0)]
public sealed class RequestInitTakeoutSession : IRequest<MyTelegram.Schema.Account.ITakeout>
{
    public uint ConstructorId => 0x8ef3eab0;
    ///<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 to export contacts
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Contacts { get; set; }

    ///<summary>
    /// Whether to export messages in private chats
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool MessageUsers { get; set; }

    ///<summary>
    /// Whether to export messages in <a href="https://corefork.telegram.org/api/channel#basic-groups">basic groups</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool MessageChats { get; set; }

    ///<summary>
    /// Whether to export messages in <a href="https://corefork.telegram.org/api/channel#supergroups">supergroups</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool MessageMegagroups { get; set; }

    ///<summary>
    /// Whether to export messages in <a href="https://corefork.telegram.org/api/channel#channels">channels</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool MessageChannels { get; set; }

    ///<summary>
    /// Whether to export files
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Files { get; set; }

    ///<summary>
    /// Maximum size of files to export
    ///</summary>
    public long? FileMaxSize { get; set; }

    public void ComputeFlag()
    {
        if (Contacts) { Flags = Flags.SetBit(0); }
        if (MessageUsers) { Flags = Flags.SetBit(1); }
        if (MessageChats) { Flags = Flags.SetBit(2); }
        if (MessageMegagroups) { Flags = Flags.SetBit(3); }
        if (MessageChannels) { Flags = Flags.SetBit(4); }
        if (Files) { Flags = Flags.SetBit(5); }
        if (/*FileMaxSize != 0 &&*/ FileMaxSize.HasValue) { Flags = Flags.SetBit(5); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(5)) { writer.Write(FileMaxSize.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Contacts = true; }
        if (Flags.IsBitSet(1)) { MessageUsers = true; }
        if (Flags.IsBitSet(2)) { MessageChats = true; }
        if (Flags.IsBitSet(3)) { MessageMegagroups = true; }
        if (Flags.IsBitSet(4)) { MessageChannels = true; }
        if (Flags.IsBitSet(5)) { Files = true; }
        if (Flags.IsBitSet(5)) { FileMaxSize = buffer.ReadInt64(); }
    }
}
