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

namespace MyTelegram.Schema;

///<summary>
/// An accepted phone call
/// See <a href="https://corefork.telegram.org/constructor/phoneCallAccepted" />
///</summary>
[TlObject(0x3660c311)]
public sealed class TPhoneCallAccepted : IPhoneCall
{
    public uint ConstructorId => 0x3660c311;
    ///<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 is a video call
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Video { get; set; }

    ///<summary>
    /// ID of accepted phone call
    ///</summary>
    public long Id { get; set; }

    ///<summary>
    /// Access hash of phone call
    ///</summary>
    public long AccessHash { get; set; }

    ///<summary>
    /// When was the call accepted
    ///</summary>
    public int Date { get; set; }

    ///<summary>
    /// ID of the call creator
    ///</summary>
    public long AdminId { get; set; }

    ///<summary>
    /// ID of the other user in the call
    ///</summary>
    public long ParticipantId { get; set; }

    ///<summary>
    /// B parameter for <a href="https://corefork.telegram.org/api/end-to-end/voice-calls">secure E2E phone call key exchange</a>
    ///</summary>
    public ReadOnlyMemory<byte> GB { get; set; }

    ///<summary>
    /// Protocol to use for phone call
    /// See <a href="https://corefork.telegram.org/type/PhoneCallProtocol" />
    ///</summary>
    public MyTelegram.Schema.IPhoneCallProtocol Protocol { get; set; }

    public void ComputeFlag()
    {
        if (Video) { Flags = Flags.SetBit(6); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Id);
        writer.Write(AccessHash);
        writer.Write(Date);
        writer.Write(AdminId);
        writer.Write(ParticipantId);
        writer.Write(GB);
        writer.Write(Protocol);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(6)) { Video = true; }
        Id = buffer.ReadInt64();
        AccessHash = buffer.ReadInt64();
        Date = buffer.ReadInt32();
        AdminId = buffer.ReadInt64();
        ParticipantId = buffer.ReadInt64();
        GB = buffer.ReadBytes();
        Protocol = buffer.Read<MyTelegram.Schema.IPhoneCallProtocol>();
    }
}