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

namespace MyTelegram.Schema.LayerN;

///<summary>
/// Initialize connection
/// See <a href="https://corefork.telegram.org/constructor/initConnection" />
///</summary>
[TlObject(0x785188b8)]
public sealed class RequestInitConnection : IRequest<IObject>, IHasSubQuery
{
    public uint ConstructorId => 0x785188b8;
    ///<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>
    /// Application identifier (see. <a href="https://corefork.telegram.org/myapp">App configuration</a>)
    ///</summary>
    public int ApiId { get; set; }

    ///<summary>
    /// Device model
    ///</summary>
    public string DeviceModel { get; set; }

    ///<summary>
    /// Operation system version
    ///</summary>
    public string SystemVersion { get; set; }

    ///<summary>
    /// Application version
    ///</summary>
    public string AppVersion { get; set; }

    ///<summary>
    /// Code for the language used on the device's OS, ISO 639-1 standard
    ///</summary>
    public string SystemLangCode { get; set; }

    ///<summary>
    /// Language pack to use
    ///</summary>
    public string LangPack { get; set; }

    ///<summary>
    /// Code for the language used on the client, ISO 639-1 standard
    ///</summary>
    public string LangCode { get; set; }

    ///<summary>
    /// Info about an MTProto proxy
    ///</summary>
    public IInputClientProxy? Proxy { get; set; }

    ///<summary>
    /// The query itself
    ///</summary>
    public IObject Query { get; set; }

    public void ComputeFlag()
    {
        if (Proxy != null) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(ApiId);
        writer.Write(DeviceModel);
        writer.Write(SystemVersion);
        writer.Write(AppVersion);
        writer.Write(SystemLangCode);
        writer.Write(LangPack);
        writer.Write(LangCode);
        if (Flags.IsBitSet(0)) { writer.Write(Proxy); }
        writer.Write(Query);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        ApiId = buffer.ReadInt32();
        DeviceModel = buffer.ReadString();
        SystemVersion = buffer.ReadString();
        AppVersion = buffer.ReadString();
        SystemLangCode = buffer.ReadString();
        LangPack = buffer.ReadString();
        LangCode = buffer.ReadString();
        if (Flags.IsBitSet(0)) { Proxy = buffer.Read<IInputClientProxy>(); }
        Query = buffer.Read<IObject>();
    }
}