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

namespace MyTelegram.Schema.Phone;

///<summary>
/// Start or stop recording a group call: the recorded audio and video streams will be automatically sent to <code>Saved messages</code> (the chat with ourselves).
/// <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 GROUPCALL_NOT_MODIFIED Group call settings weren't modified.
/// See <a href="https://corefork.telegram.org/method/phone.toggleGroupCallRecord" />
///</summary>
[TlObject(0xf128c708)]
public sealed class RequestToggleGroupCallRecord : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0xf128c708;
    ///<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 start or stop recording
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Start { get; set; }

    ///<summary>
    /// Whether to also record video streams
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Video { get; set; }

    ///<summary>
    /// The group call or livestream
    /// See <a href="https://corefork.telegram.org/type/InputGroupCall" />
    ///</summary>
    public MyTelegram.Schema.IInputGroupCall Call { get; set; }

    ///<summary>
    /// Recording title
    ///</summary>
    public string? Title { get; set; }

    ///<summary>
    /// If video stream recording is enabled, whether to record in portrait or landscape mode
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? VideoPortrait { get; set; }

    public void ComputeFlag()
    {
        if (Start) { Flags = Flags.SetBit(0); }
        if (Video) { Flags = Flags.SetBit(2); }
        if (Title != null) { Flags = Flags.SetBit(1); }
        if (VideoPortrait !=null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Call);
        if (Flags.IsBitSet(1)) { writer.Write(Title); }
        if (Flags.IsBitSet(2)) { writer.Write(VideoPortrait.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Start = true; }
        if (Flags.IsBitSet(2)) { Video = true; }
        Call = buffer.Read<MyTelegram.Schema.IInputGroupCall>();
        if (Flags.IsBitSet(1)) { Title = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { VideoPortrait = buffer.Read(); }
    }
}
