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

namespace MyTelegram.Schema.Payments;

///<summary>
/// Fetch <a href="https://corefork.telegram.org/api/stars#balance-and-transaction-history">Telegram Stars transactions</a>.The <code>inbound</code> and <code>outbound</code> flags are mutually exclusive: if none of the two are set, both incoming and outgoing transactions are fetched.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHAT_ADMIN_REQUIRED You must be an admin in this chat to do this.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// See <a href="https://corefork.telegram.org/method/payments.getStarsTransactions" />
///</summary>
[TlObject(0x69da4557)]
public sealed class RequestGetStarsTransactions : IRequest<MyTelegram.Schema.Payments.IStarsStatus>
{
    public uint ConstructorId => 0x69da4557;
    ///<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>
    /// If set, fetches only incoming transactions.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Inbound { get; set; }

    ///<summary>
    /// If set, fetches only outgoing transactions.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Outbound { get; set; }

    ///<summary>
    /// Return transactions in ascending order by date (instead of descending order by date).
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Ascending { get; set; }
    public bool Ton { get; set; }

    ///<summary>
    /// If set, fetches only transactions for the specified <a href="https://corefork.telegram.org/api/stars#star-subscriptions">Telegram Star subscription »</a>.
    ///</summary>
    public string? SubscriptionId { get; set; }

    ///<summary>
    /// Fetch the transaction history of the peer (<a href="https://corefork.telegram.org/constructor/inputPeerSelf">inputPeerSelf</a> or a bot we own).
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/offsets">Offset for pagination, obtained from the returned <code>next_offset</code>, initially an empty string »</a>.
    ///</summary>
    public string Offset { get; set; }

    ///<summary>
    /// Maximum number of results to return, <a href="https://corefork.telegram.org/api/offsets">see pagination</a>
    ///</summary>
    public int Limit { get; set; }

    public void ComputeFlag()
    {
        if (Inbound) { Flags = Flags.SetBit(0); }
        if (Outbound) { Flags = Flags.SetBit(1); }
        if (Ascending) { Flags = Flags.SetBit(2); }
        if (Ton) { Flags = Flags.SetBit(4); }
        if (SubscriptionId != null) { Flags = Flags.SetBit(3); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(3)) { writer.Write(SubscriptionId); }
        writer.Write(Peer);
        writer.Write(Offset);
        writer.Write(Limit);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Inbound = true; }
        if (Flags.IsBitSet(1)) { Outbound = true; }
        if (Flags.IsBitSet(2)) { Ascending = true; }
        if (Flags.IsBitSet(4)) { Ton = true; }
        if (Flags.IsBitSet(3)) { SubscriptionId = buffer.ReadString(); }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        Offset = buffer.ReadString();
        Limit = buffer.ReadInt32();
    }
}
