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

namespace MyTelegram.Schema.LayerN;

///<summary>
/// Protocol info for libtgvoip
/// See <a href="https://corefork.telegram.org/constructor/phoneCallProtocol" />
///</summary>
[TlObject(0xa2bb35cb)]
public sealed class TPhoneCallProtocolLayerN : IPhoneCallProtocol
{
    public uint ConstructorId => 0xa2bb35cb;
    ///<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 to allow P2P connection to the other participant
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool UdpP2p { get; set; }

    ///<summary>
    /// Whether to allow connection to the other participants through the reflector servers
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool UdpReflector { get; set; }

    ///<summary>
    /// Minimum layer for remote libtgvoip
    ///</summary>
    public int MinLayer { get; set; }

    ///<summary>
    /// Maximum layer for remote libtgvoip
    ///</summary>
    public int MaxLayer { get; set; }

    public TVector<string> LibraryVersions { get; set; }

    public void ComputeFlag()
    {
        if (UdpP2p) { Flags = Flags.SetBit(0); }
        if (UdpReflector) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(MinLayer);
        writer.Write(MaxLayer);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { UdpP2p = true; }
        if (Flags.IsBitSet(1)) { UdpReflector = true; }
        MinLayer = buffer.ReadInt32();
        MaxLayer = buffer.ReadInt32();
    }
}