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

namespace MyTelegram.Schema.Phone;

///<summary>
/// Edit information about a given group call participantNote: <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">flags</a>.N?<a href="https://corefork.telegram.org/type/Bool">Bool</a> parameters can have three possible values:
/// <para>Possible errors</para>
/// Code Type Description
/// 403 GROUPCALL_FORBIDDEN The group call has already ended.
/// 400 GROUPCALL_INVALID The specified group call is invalid.
/// 400 PARTICIPANT_JOIN_MISSING Trying to enable a presentation, when the user hasn't joined the Video Chat with <a href="https://corefork.telegram.org/method/phone.joinGroupCall">phone.joinGroupCall</a>.
/// 400 RAISE_HAND_FORBIDDEN You cannot raise your hand.
/// 400 USER_VOLUME_INVALID The specified user volume is invalid.
/// 400 VIDEO_PAUSE_FORBIDDEN You cannot pause the video stream.
/// 400 VIDEO_STOP_FORBIDDEN You cannot stop the video stream.
/// See <a href="https://corefork.telegram.org/method/phone.editGroupCallParticipant" />
///</summary>
[TlObject(0xa5273abf)]
public sealed class RequestEditGroupCallParticipant : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0xa5273abf;
    ///<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>
    /// The group call
    /// See <a href="https://corefork.telegram.org/type/InputGroupCall" />
    ///</summary>
    public MyTelegram.Schema.IInputGroupCall Call { get; set; }

    ///<summary>
    /// The group call participant (can also be the user itself)
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Participant { get; set; }

    ///<summary>
    /// Whether to mute or unmute the specified participant
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? Muted { get; set; }

    ///<summary>
    /// New volume
    ///</summary>
    public int? Volume { get; set; }

    ///<summary>
    /// Raise or lower hand
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? RaiseHand { get; set; }

    ///<summary>
    /// Start or stop the video stream
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? VideoStopped { get; set; }

    ///<summary>
    /// Pause or resume the video stream
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? VideoPaused { get; set; }

    ///<summary>
    /// Pause or resume the screen sharing stream
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? PresentationPaused { get; set; }

    public void ComputeFlag()
    {
        if (Muted !=null) { Flags = Flags.SetBit(0); }
        if (/*Volume != 0 && */Volume.HasValue) { Flags = Flags.SetBit(1); }
        if (RaiseHand !=null) { Flags = Flags.SetBit(2); }
        if (VideoStopped !=null) { Flags = Flags.SetBit(3); }
        if (VideoPaused !=null) { Flags = Flags.SetBit(4); }
        if (PresentationPaused !=null) { Flags = Flags.SetBit(5); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Call);
        writer.Write(Participant);
        if (Flags.IsBitSet(0)) { writer.Write(Muted.Value); }
        if (Flags.IsBitSet(1)) { writer.Write(Volume.Value); }
        if (Flags.IsBitSet(2)) { writer.Write(RaiseHand.Value); }
        if (Flags.IsBitSet(3)) { writer.Write(VideoStopped.Value); }
        if (Flags.IsBitSet(4)) { writer.Write(VideoPaused.Value); }
        if (Flags.IsBitSet(5)) { writer.Write(PresentationPaused.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Call = buffer.Read<MyTelegram.Schema.IInputGroupCall>();
        Participant = buffer.Read<MyTelegram.Schema.IInputPeer>();
        if (Flags.IsBitSet(0)) { Muted = buffer.Read(); }
        if (Flags.IsBitSet(1)) { Volume = buffer.ReadInt32(); }
        if (Flags.IsBitSet(2)) { RaiseHand = buffer.Read(); }
        if (Flags.IsBitSet(3)) { VideoStopped = buffer.Read(); }
        if (Flags.IsBitSet(4)) { VideoPaused = buffer.Read(); }
        if (Flags.IsBitSet(5)) { PresentationPaused = buffer.Read(); }
    }
}
