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

namespace MyTelegram.Schema;

///<summary>
/// A language pack string which has different forms based on the number of some object it mentions. See <a href="https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html">https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html</a> for more info
/// See <a href="https://corefork.telegram.org/constructor/langPackStringPluralized" />
///</summary>
[TlObject(0x6c47ac9f)]
public sealed class TLangPackStringPluralized : ILangPackString
{
    public uint ConstructorId => 0x6c47ac9f;
    ///<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>
    /// Localization key
    ///</summary>
    public string Key { get; set; }

    ///<summary>
    /// Value for zero objects
    ///</summary>
    public string? ZeroValue { get; set; }

    ///<summary>
    /// Value for one object
    ///</summary>
    public string? OneValue { get; set; }

    ///<summary>
    /// Value for two objects
    ///</summary>
    public string? TwoValue { get; set; }

    ///<summary>
    /// Value for a few objects
    ///</summary>
    public string? FewValue { get; set; }

    ///<summary>
    /// Value for many objects
    ///</summary>
    public string? ManyValue { get; set; }

    ///<summary>
    /// Default value
    ///</summary>
    public string OtherValue { get; set; }

    public void ComputeFlag()
    {
        if (ZeroValue != null) { Flags = Flags.SetBit(0); }
        if (OneValue != null) { Flags = Flags.SetBit(1); }
        if (TwoValue != null) { Flags = Flags.SetBit(2); }
        if (FewValue != null) { Flags = Flags.SetBit(3); }
        if (ManyValue != null) { Flags = Flags.SetBit(4); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Key);
        if (Flags.IsBitSet(0)) { writer.Write(ZeroValue); }
        if (Flags.IsBitSet(1)) { writer.Write(OneValue); }
        if (Flags.IsBitSet(2)) { writer.Write(TwoValue); }
        if (Flags.IsBitSet(3)) { writer.Write(FewValue); }
        if (Flags.IsBitSet(4)) { writer.Write(ManyValue); }
        writer.Write(OtherValue);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Key = buffer.ReadString();
        if (Flags.IsBitSet(0)) { ZeroValue = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { OneValue = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { TwoValue = buffer.ReadString(); }
        if (Flags.IsBitSet(3)) { FewValue = buffer.ReadString(); }
        if (Flags.IsBitSet(4)) { ManyValue = buffer.ReadString(); }
        OtherValue = buffer.ReadString();
    }
}