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

namespace MyTelegram.Schema;

///<summary>
/// Used to download an album cover for any music file using <a href="https://corefork.telegram.org/method/upload.getWebFile">upload.getWebFile</a>, see the <a href="https://corefork.telegram.org/api/files#downloading-webfiles">webfile docs for more info »</a>.
/// See <a href="https://corefork.telegram.org/constructor/inputWebFileAudioAlbumThumbLocation" />
///</summary>
[TlObject(0xf46fe924)]
public sealed class TInputWebFileAudioAlbumThumbLocation : IInputWebFileLocation
{
    public uint ConstructorId => 0xf46fe924;
    ///<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>
    /// Used to return a thumbnail with <code>100x100</code> resolution (instead of the default <code>600x600</code>)
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Small { get; set; }

    ///<summary>
    /// The audio file in question: must NOT be provided in secret chats, provide the <code>title</code> and <code>performer</code> fields instead.
    /// See <a href="https://corefork.telegram.org/type/InputDocument" />
    ///</summary>
    public MyTelegram.Schema.IInputDocument? Document { get; set; }

    ///<summary>
    /// Song title: should only be used in secret chats, in normal chats provide <code>document</code> instead, as it has more lax rate limits.
    ///</summary>
    public string? Title { get; set; }

    ///<summary>
    /// Song performer: should only be used in secret chats, in normal chats provide <code>document</code> instead, as it has more lax rate limits.
    ///</summary>
    public string? Performer { get; set; }

    public void ComputeFlag()
    {
        if (Small) { Flags = Flags.SetBit(2); }
        if (Document != null) { Flags = Flags.SetBit(0); }
        if (Title != null) { Flags = Flags.SetBit(1); }
        if (Performer != null) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(Document); }
        if (Flags.IsBitSet(1)) { writer.Write(Title); }
        if (Flags.IsBitSet(1)) { writer.Write(Performer); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(2)) { Small = true; }
        if (Flags.IsBitSet(0)) { Document = buffer.Read<MyTelegram.Schema.IInputDocument>(); }
        if (Flags.IsBitSet(1)) { Title = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { Performer = buffer.ReadString(); }
    }
}