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

namespace MyTelegram.Schema;

///<summary>
/// Indicates a peer that can be used to send messages
/// See <a href="https://corefork.telegram.org/constructor/sendAsPeer" />
///</summary>
[TlObject(0xb81c7034)]
public sealed class TSendAsPeer : ISendAsPeer
{
    public uint ConstructorId => 0xb81c7034;
    ///<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>
    /// Whether a Telegram Premium account is required to send messages as this peer
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool PremiumRequired { get; set; }

    ///<summary>
    /// Peer
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer Peer { get; set; }

    public void ComputeFlag()
    {
        if (PremiumRequired) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { PremiumRequired = true; }
        Peer = buffer.Read<MyTelegram.Schema.IPeer>();
    }
}