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

namespace MyTelegram.Schema;

///<summary>
/// Info about a <a href="https://corefork.telegram.org/api/channel">channel/supergroup</a>, shared by a user with the currently logged in bot using <a href="https://corefork.telegram.org/method/messages.sendBotRequestedPeer">messages.sendBotRequestedPeer</a>.All fields except the ID are optional, and will be populated if present on the chosen channel/supergroup, according to the parameters of the requesting <a href="https://corefork.telegram.org/constructor/inputKeyboardButtonRequestPeer">inputKeyboardButtonRequestPeer</a>.
/// See <a href="https://corefork.telegram.org/constructor/requestedPeerChannel" />
///</summary>
[TlObject(0x8ba403e4)]
public sealed class TRequestedPeerChannel : IRequestedPeer
{
    public uint ConstructorId => 0x8ba403e4;
    ///<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>
    /// Channel/supergroup ID.
    ///</summary>
    public long ChannelId { get; set; }

    ///<summary>
    /// Channel/supergroup title.
    ///</summary>
    public string? Title { get; set; }

    ///<summary>
    /// Channel/supergroup username.
    ///</summary>
    public string? Username { get; set; }

    ///<summary>
    /// Channel/supergroup photo.
    /// See <a href="https://corefork.telegram.org/type/Photo" />
    ///</summary>
    public MyTelegram.Schema.IPhoto? Photo { get; set; }

    public void ComputeFlag()
    {
        if (Title != null) { Flags = Flags.SetBit(0); }
        if (Username != null) { Flags = Flags.SetBit(1); }
        if (Photo != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(ChannelId);
        if (Flags.IsBitSet(0)) { writer.Write(Title); }
        if (Flags.IsBitSet(1)) { writer.Write(Username); }
        if (Flags.IsBitSet(2)) { writer.Write(Photo); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        ChannelId = buffer.ReadInt64();
        if (Flags.IsBitSet(0)) { Title = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { Username = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { Photo = buffer.Read<MyTelegram.Schema.IPhoto>(); }
    }
}