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

namespace MyTelegram.Schema.Phone;

///<summary>
/// See <a href="https://corefork.telegram.org/method/phone.createConferenceCall" />
///</summary>
[TlObject(0x7d0444bb)]
public sealed class RequestCreateConferenceCall : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0x7d0444bb;
    public int Flags { get; set; }
    public bool Muted { get; set; }
    public bool VideoStopped { get; set; }
    public bool Join { get; set; }
    public int RandomId { get; set; }
    public ReadOnlyMemory<byte>? PublicKey { get; set; }
    public byte[]? Block { get; set; }
    public MyTelegram.Schema.IDataJSON? Params { get; set; }

    public void ComputeFlag()
    {
        if (Muted) { Flags = Flags.SetBit(0); }
        if (VideoStopped) { Flags = Flags.SetBit(2); }
        if (Join) { Flags = Flags.SetBit(3); }
        if (PublicKey != null) { Flags = Flags.SetBit(3); }
        if (Block != null) { Flags = Flags.SetBit(3); }
        if (Params != null) { Flags = Flags.SetBit(3); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(RandomId);
        if (Flags.IsBitSet(3)) { writer.WriteRawBytes(PublicKey); }
        if (Flags.IsBitSet(3)) { writer.Write(Block); }
        if (Flags.IsBitSet(3)) { writer.Write(Params); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Muted = true; }
        if (Flags.IsBitSet(2)) { VideoStopped = true; }
        if (Flags.IsBitSet(3)) { Join = true; }
        RandomId = buffer.ReadInt32();
        if (Flags.IsBitSet(3)) { PublicKey = buffer.ReadInt256(); }
        if (Flags.IsBitSet(3)) { Block = buffer.ReadBytes(); }
        if (Flags.IsBitSet(3)) { Params = buffer.Read<MyTelegram.Schema.IDataJSON>(); }
    }
}
