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

namespace MyTelegram.Schema.Account;

///<summary>
/// <a href="https://corefork.telegram.org/passport">Telegram Passport</a> authorization form
/// See <a href="https://corefork.telegram.org/constructor/account.authorizationForm" />
///</summary>
[TlObject(0xad2e1cd8)]
public sealed class TAuthorizationForm : IAuthorizationForm
{
    public uint ConstructorId => 0xad2e1cd8;
    ///<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>
    /// Required <a href="https://corefork.telegram.org/passport">Telegram Passport</a> documents
    ///</summary>
    public TVector<MyTelegram.Schema.ISecureRequiredType> RequiredTypes { get; set; }

    ///<summary>
    /// Already submitted <a href="https://corefork.telegram.org/passport">Telegram Passport</a> documents
    ///</summary>
    public TVector<MyTelegram.Schema.ISecureValue> Values { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/passport">Telegram Passport</a> errors
    ///</summary>
    public TVector<MyTelegram.Schema.ISecureValueError> Errors { get; set; }

    ///<summary>
    /// Info about the bot to which the form will be submitted
    ///</summary>
    public TVector<MyTelegram.Schema.IUser> Users { get; set; }

    ///<summary>
    /// URL of the service's privacy policy
    ///</summary>
    public string? PrivacyPolicyUrl { get; set; }

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

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(RequiredTypes);
        writer.Write(Values);
        writer.Write(Errors);
        writer.Write(Users);
        if (Flags.IsBitSet(0)) { writer.Write(PrivacyPolicyUrl); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        RequiredTypes = buffer.Read<TVector<MyTelegram.Schema.ISecureRequiredType>>();
        Values = buffer.Read<TVector<MyTelegram.Schema.ISecureValue>>();
        Errors = buffer.Read<TVector<MyTelegram.Schema.ISecureValueError>>();
        Users = buffer.Read<TVector<MyTelegram.Schema.IUser>>();
        if (Flags.IsBitSet(0)) { PrivacyPolicyUrl = buffer.ReadString(); }
    }
}