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

namespace MyTelegram.Schema;

///<summary>
/// Payment credentials
/// See <a href="https://corefork.telegram.org/constructor/inputPaymentCredentials" />
///</summary>
[TlObject(0x3417d728)]
public sealed class TInputPaymentCredentials : IInputPaymentCredentials
{
    public uint ConstructorId => 0x3417d728;
    ///<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>
    /// Save payment credential for future use
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Save { get; set; }

    ///<summary>
    /// Payment credentials
    /// See <a href="https://corefork.telegram.org/type/DataJSON" />
    ///</summary>
    public MyTelegram.Schema.IDataJSON Data { get; set; }

    public void ComputeFlag()
    {
        if (Save) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Data);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Save = true; }
        Data = buffer.Read<MyTelegram.Schema.IDataJSON>();
    }
}