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

namespace MyTelegram.Schema;

///<summary>
/// Group profile photo.
/// See <a href="https://corefork.telegram.org/constructor/chatPhoto" />
///</summary>
[TlObject(0x1c6e1c11)]
public sealed class TChatPhoto : IChatPhoto
{
    public uint ConstructorId => 0x1c6e1c11;
    ///<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 the user has an animated profile picture
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool HasVideo { get; set; }

    ///<summary>
    /// Photo ID
    ///</summary>
    public long PhotoId { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/files#stripped-thumbnails">Stripped thumbnail</a>
    ///</summary>
    public ReadOnlyMemory<byte>? StrippedThumb { get; set; }

    ///<summary>
    /// DC where this photo is stored
    ///</summary>
    public int DcId { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(PhotoId);
        if (Flags.IsBitSet(1)) { writer.Write(StrippedThumb); }
        writer.Write(DcId);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { HasVideo = true; }
        PhotoId = buffer.ReadInt64();
        if (Flags.IsBitSet(1)) { StrippedThumb = buffer.ReadBytes(); }
        DcId = buffer.ReadInt32();
    }
}