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

namespace MyTelegram.Schema.Payments;

///<summary>
/// Validated user-provided info
/// See <a href="https://corefork.telegram.org/constructor/payments.validatedRequestedInfo" />
///</summary>
[TlObject(0xd1451883)]
public sealed class TValidatedRequestedInfo : IValidatedRequestedInfo
{
    public uint ConstructorId => 0xd1451883;
    ///<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>
    /// ID
    ///</summary>
    public string? Id { get; set; }

    ///<summary>
    /// Shipping options
    ///</summary>
    public TVector<MyTelegram.Schema.IShippingOption>? ShippingOptions { get; set; }

    public void ComputeFlag()
    {
        if (Id != null) { Flags = Flags.SetBit(0); }
        if (ShippingOptions?.Count > 0) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(Id); }
        if (Flags.IsBitSet(1)) { writer.Write(ShippingOptions); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Id = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { ShippingOptions = buffer.Read<TVector<MyTelegram.Schema.IShippingOption>>(); }
    }
}