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

namespace MyTelegram.Schema;

///<summary>
/// New photo to be set as group profile photo.The <code>file</code>, <code>video</code> and <code>video_emoji_markup</code> flags are mutually exclusive.
/// See <a href="https://corefork.telegram.org/constructor/inputChatUploadedPhoto" />
///</summary>
[TlObject(0xbdcdaec0)]
public sealed class TInputChatUploadedPhoto : IInputChatPhoto
{
    public uint ConstructorId => 0xbdcdaec0;
    ///<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>
    /// File saved in parts using the method <a href="https://corefork.telegram.org/method/upload.saveFilePart">upload.saveFilePart</a>
    /// See <a href="https://corefork.telegram.org/type/InputFile" />
    ///</summary>
    public MyTelegram.Schema.IInputFile? File { get; set; }

    ///<summary>
    /// Square video for animated profile picture
    /// See <a href="https://corefork.telegram.org/type/InputFile" />
    ///</summary>
    public MyTelegram.Schema.IInputFile? Video { get; set; }

    ///<summary>
    /// Floating point UNIX timestamp in seconds, indicating the frame of the video/sticker that should be used as static preview; can only be used if <code>video</code> or <code>video_emoji_markup</code> is set.
    ///</summary>
    public double? VideoStartTs { get; set; }

    ///<summary>
    /// Animated sticker profile picture, must contain either a <a href="https://corefork.telegram.org/constructor/videoSizeEmojiMarkup">videoSizeEmojiMarkup</a> or a <a href="https://corefork.telegram.org/constructor/videoSizeStickerMarkup">videoSizeStickerMarkup</a> constructor.
    /// See <a href="https://corefork.telegram.org/type/VideoSize" />
    ///</summary>
    public MyTelegram.Schema.IVideoSize? VideoEmojiMarkup { get; set; }

    public void ComputeFlag()
    {
        if (File != null) { Flags = Flags.SetBit(0); }
        if (Video != null) { Flags = Flags.SetBit(1); }
        if (VideoStartTs>0) { Flags = Flags.SetBit(2); }
        if (VideoEmojiMarkup != null) { Flags = Flags.SetBit(3); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(File); }
        if (Flags.IsBitSet(1)) { writer.Write(Video); }
        if (Flags.IsBitSet(2)) { writer.Write(VideoStartTs.Value); }
        if (Flags.IsBitSet(3)) { writer.Write(VideoEmojiMarkup); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { File = buffer.Read<MyTelegram.Schema.IInputFile>(); }
        if (Flags.IsBitSet(1)) { Video = buffer.Read<MyTelegram.Schema.IInputFile>(); }
        if (Flags.IsBitSet(2)) { VideoStartTs = buffer.ReadDouble(); }
        if (Flags.IsBitSet(3)) { VideoEmojiMarkup = buffer.Read<MyTelegram.Schema.IVideoSize>(); }
    }
}