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

namespace MyTelegram.Schema.Photos;

///<summary>
/// Upload a custom profile picture for a contact, or suggest a new profile picture to a contact.The <code>file</code>, <code>video</code> and <code>video_emoji_markup</code> flags are mutually exclusive.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CONTACT_MISSING The specified user is not a contact.
/// 400 USER_ID_INVALID The provided user ID is invalid.
/// See <a href="https://corefork.telegram.org/method/photos.uploadContactProfilePhoto" />
///</summary>
[TlObject(0xe14c4a71)]
public sealed class RequestUploadContactProfilePhoto : IRequest<MyTelegram.Schema.Photos.IPhoto>
{
    public uint ConstructorId => 0xe14c4a71;
    ///<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>
    /// If set, will send a <a href="https://corefork.telegram.org/constructor/messageActionSuggestProfilePhoto">messageActionSuggestProfilePhoto</a> service message to <code>user_id</code>, suggesting them to use the specified profile picture; otherwise, will set a personal profile picture for the user (only visible to the current user).
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Suggest { get; set; }

    ///<summary>
    /// If set, removes a previously set personal profile picture (does not affect suggested profile pictures, to remove them simply deleted the <a href="https://corefork.telegram.org/constructor/messageActionSuggestProfilePhoto">messageActionSuggestProfilePhoto</a> service message with <a href="https://corefork.telegram.org/method/messages.deleteMessages">messages.deleteMessages</a>).
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Save { get; set; }

    ///<summary>
    /// The contact
    /// See <a href="https://corefork.telegram.org/type/InputUser" />
    ///</summary>
    public MyTelegram.Schema.IInputUser UserId { get; set; }

    ///<summary>
    /// Profile photo
    /// See <a href="https://corefork.telegram.org/type/InputFile" />
    ///</summary>
    public MyTelegram.Schema.IInputFile? File { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/files#animated-profile-pictures">Animated profile picture</a> video
    /// 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 (Suggest) { Flags = Flags.SetBit(3); }
        if (Save) { Flags = Flags.SetBit(4); }
        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(5); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(UserId);
        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(5)) { writer.Write(VideoEmojiMarkup); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(3)) { Suggest = true; }
        if (Flags.IsBitSet(4)) { Save = true; }
        UserId = buffer.Read<MyTelegram.Schema.IInputUser>();
        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(5)) { VideoEmojiMarkup = buffer.Read<MyTelegram.Schema.IVideoSize>(); }
    }
}
