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

namespace MyTelegram.Schema;

///<summary>
/// <a href="https://corefork.telegram.org/api/profile#birthday">Birthday</a> information for a user.Also used to invite users to gift <a href="https://corefork.telegram.org/api/premium#gifting-telegram-premium">Telegram Premium subscriptions »</a> to other users with birthdays within a +1/-1 day time range, related to the current day.
/// See <a href="https://corefork.telegram.org/constructor/birthday" />
///</summary>
[TlObject(0x6c8e1e06)]
public sealed class TBirthday : IBirthday
{
    public uint ConstructorId => 0x6c8e1e06;
    ///<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>
    /// Birth day
    ///</summary>
    public int Day { get; set; }

    ///<summary>
    /// Birth month
    ///</summary>
    public int Month { get; set; }

    ///<summary>
    /// (Optional) birth year.
    ///</summary>
    public int? Year { get; set; }

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

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Day);
        writer.Write(Month);
        if (Flags.IsBitSet(0)) { writer.Write(Year.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Day = buffer.ReadInt32();
        Month = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Year = buffer.ReadInt32(); }
    }
}