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

namespace MyTelegram.Schema.Payments;

///<summary>
/// See <a href="https://corefork.telegram.org/method/payments.getResaleStarGifts" />
///</summary>
[TlObject(0x7a5fa236)]
public sealed class RequestGetResaleStarGifts : IRequest<MyTelegram.Schema.Payments.IResaleStarGifts>
{
    public uint ConstructorId => 0x7a5fa236;
    public int Flags { get; set; }
    public bool SortByPrice { get; set; }
    public bool SortByNum { get; set; }
    public long? AttributesHash { get; set; }
    public long GiftId { get; set; }
    public TVector<MyTelegram.Schema.IStarGiftAttributeId>? Attributes { get; set; }
    public string Offset { get; set; }
    public int Limit { get; set; }

    public void ComputeFlag()
    {
        if (SortByPrice) { Flags = Flags.SetBit(1); }
        if (SortByNum) { Flags = Flags.SetBit(2); }
        if (/*AttributesHash != 0 &&*/ AttributesHash.HasValue) { Flags = Flags.SetBit(0); }
        if (Attributes?.Count > 0) { Flags = Flags.SetBit(3); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(AttributesHash.Value); }
        writer.Write(GiftId);
        if (Flags.IsBitSet(3)) { writer.Write(Attributes); }
        writer.Write(Offset);
        writer.Write(Limit);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { SortByPrice = true; }
        if (Flags.IsBitSet(2)) { SortByNum = true; }
        if (Flags.IsBitSet(0)) { AttributesHash = buffer.ReadInt64(); }
        GiftId = buffer.ReadInt64();
        if (Flags.IsBitSet(3)) { Attributes = buffer.Read<TVector<MyTelegram.Schema.IStarGiftAttributeId>>(); }
        Offset = buffer.ReadString();
        Limit = buffer.ReadInt32();
    }
}
