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

namespace MyTelegram.Schema;

///<summary>
/// Forwarded photo
/// See <a href="https://corefork.telegram.org/constructor/inputMediaPhoto" />
///</summary>
[TlObject(0xb3ba0635)]
public sealed class TInputMediaPhoto : IInputMedia
{
    public uint ConstructorId => 0xb3ba0635;
    ///<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>
    /// Photo to be forwarded
    /// See <a href="https://corefork.telegram.org/type/InputPhoto" />
    ///</summary>
    public MyTelegram.Schema.IInputPhoto Id { 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(1); }
        if (/*TtlSeconds != 0 && */TtlSeconds.HasValue) { Flags = Flags.SetBit(0); }
    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { Spoiler = true; }
        Id = buffer.Read<MyTelegram.Schema.IInputPhoto>();
        if (Flags.IsBitSet(0)) { TtlSeconds = buffer.ReadInt32(); }
    }
}