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

namespace MyTelegram.Schema.Payments;

///<summary>
/// Withdraw funds from a channel or bot's <a href="https://corefork.telegram.org/api/stars#withdrawing-stars">star balance »</a>.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 PASSWORD_HASH_INVALID The provided password hash is invalid.
/// 400 PASSWORD_MISSING You must <a href="https://corefork.telegram.org/api/srp">enable 2FA</a> before executing this operation.
/// 400 PASSWORD_TOO_FRESH_%d The password was modified less than 24 hours ago, try again in %d seconds.
/// See <a href="https://corefork.telegram.org/method/payments.getStarsRevenueWithdrawalUrl" />
///</summary>
[TlObject(0x2433dc92)]
public sealed class RequestGetStarsRevenueWithdrawalUrl : IRequest<MyTelegram.Schema.Payments.IStarsRevenueWithdrawalUrl>
{
    public uint ConstructorId => 0x2433dc92;
    public int Flags { get; set; }
    public bool Ton { get; set; }

    ///<summary>
    /// Channel or bot from which to withdraw funds.
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }
    public long? Amount { get; set; }

    ///<summary>
    /// 2FA password, see <a href="https://corefork.telegram.org/api/srp#using-the-2fa-password">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/InputCheckPasswordSRP" />
    ///</summary>
    public MyTelegram.Schema.IInputCheckPasswordSRP Password { get; set; }

    public void ComputeFlag()
    {
        if (Ton) { Flags = Flags.SetBit(0); }
        if (/*Amount != 0 &&*/ Amount.HasValue) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        if (Flags.IsBitSet(1)) { writer.Write(Amount.Value); }
        writer.Write(Password);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Ton = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        if (Flags.IsBitSet(1)) { Amount = buffer.ReadInt64(); }
        Password = buffer.Read<MyTelegram.Schema.IInputCheckPasswordSRP>();
    }
}
