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

namespace MyTelegram.Schema;

///<summary>
/// Order info provided by the user
/// See <a href="https://corefork.telegram.org/constructor/paymentRequestedInfo" />
///</summary>
[TlObject(0x909c3f94)]
public sealed class TPaymentRequestedInfo : IPaymentRequestedInfo
{
    public uint ConstructorId => 0x909c3f94;
    ///<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>
    /// User's full name
    ///</summary>
    public string? Name { get; set; }

    ///<summary>
    /// User's phone number
    ///</summary>
    public string? Phone { get; set; }

    ///<summary>
    /// User's email address
    ///</summary>
    public string? Email { get; set; }

    ///<summary>
    /// User's shipping address
    /// See <a href="https://corefork.telegram.org/type/PostAddress" />
    ///</summary>
    public MyTelegram.Schema.IPostAddress? ShippingAddress { get; set; }

    public void ComputeFlag()
    {
        if (Name != null) { Flags = Flags.SetBit(0); }
        if (Phone != null) { Flags = Flags.SetBit(1); }
        if (Email != null) { Flags = Flags.SetBit(2); }
        if (ShippingAddress != null) { Flags = Flags.SetBit(3); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(Name); }
        if (Flags.IsBitSet(1)) { writer.Write(Phone); }
        if (Flags.IsBitSet(2)) { writer.Write(Email); }
        if (Flags.IsBitSet(3)) { writer.Write(ShippingAddress); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Name = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { Phone = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { Email = buffer.ReadString(); }
        if (Flags.IsBitSet(3)) { ShippingAddress = buffer.Read<MyTelegram.Schema.IPostAddress>(); }
    }
}