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

namespace MyTelegram.Schema;

///<summary>
/// Photo
/// See <a href="https://corefork.telegram.org/constructor/inputMediaUploadedPhoto" />
///</summary>
[TlObject(0x1e287d04)]
public sealed class TInputMediaUploadedPhoto : IInputMedia
{
    public uint ConstructorId => 0x1e287d04;
    ///<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 this media should be hidden behind a spoiler warning
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Spoiler { get; set; }

    ///<summary>
    /// The <a href="https://corefork.telegram.org/api/files">uploaded file</a>
    /// See <a href="https://corefork.telegram.org/type/InputFile" />
    ///</summary>
    public MyTelegram.Schema.IInputFile File { get; set; }

    ///<summary>
    /// Attached mask stickers
    ///</summary>
    public TVector<MyTelegram.Schema.IInputDocument>? Stickers { get; set; }

    ///<summary>
    /// Time to live in seconds of self-destructing photo
    ///</summary>
    public int? TtlSeconds { get; set; }

    public void ComputeFlag()
    {
        if (Spoiler) { Flags = Flags.SetBit(2); }
        if (Stickers?.Count > 0) { Flags = Flags.SetBit(0); }
        if (/*TtlSeconds != 0 && */TtlSeconds.HasValue) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(File);
        if (Flags.IsBitSet(0)) { writer.Write(Stickers); }
        if (Flags.IsBitSet(1)) { writer.Write(TtlSeconds.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(2)) { Spoiler = true; }
        File = buffer.Read<MyTelegram.Schema.IInputFile>();
        if (Flags.IsBitSet(0)) { Stickers = buffer.Read<TVector<MyTelegram.Schema.IInputDocument>>(); }
        if (Flags.IsBitSet(1)) { TtlSeconds = buffer.ReadInt32(); }
    }
}