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

namespace MyTelegram.Schema;

///<summary>
/// Full info about a <a href="https://corefork.telegram.org/api/channel#basic-groups">basic group</a>.When updating the <a href="https://corefork.telegram.org/api/peers">local peer database »</a>, all fields from the newly received constructor take priority over the old constructor cached locally (including by removing fields that aren't set in the new constructor).
/// See <a href="https://corefork.telegram.org/constructor/chatFull" />
///</summary>
[TlObject(0x2633421b)]
public sealed class TChatFull : MyTelegram.Schema.IChatFull, ILayeredChatFull
{
    public uint ConstructorId => 0x2633421b;
    ///<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>
    /// Can we change the username of this chat
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool CanSetUsername { get; set; }

    ///<summary>
    /// Whether <a href="https://corefork.telegram.org/api/scheduled-messages">scheduled messages</a> are available
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool HasScheduled { get; set; }

    ///<summary>
    /// Whether the <a href="https://corefork.telegram.org/api/translation">real-time chat translation popup</a> should be hidden.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool TranslationsDisabled { get; set; }

    ///<summary>
    /// ID of the chat
    ///</summary>
    public long Id { get; set; }

    ///<summary>
    /// About string for this chat
    ///</summary>
    public string About { get; set; }

    ///<summary>
    /// Participant list
    /// See <a href="https://corefork.telegram.org/type/ChatParticipants" />
    ///</summary>
    public MyTelegram.Schema.IChatParticipants Participants { get; set; }

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

    ///<summary>
    /// Notification settings
    /// See <a href="https://corefork.telegram.org/type/PeerNotifySettings" />
    ///</summary>
    public MyTelegram.Schema.IPeerNotifySettings NotifySettings { get; set; }

    ///<summary>
    /// Chat invite
    /// See <a href="https://corefork.telegram.org/type/ExportedChatInvite" />
    ///</summary>
    public MyTelegram.Schema.IExportedChatInvite? ExportedInvite { get; set; }

    ///<summary>
    /// Info about bots that are in this chat
    ///</summary>
    public TVector<MyTelegram.Schema.IBotInfo>? BotInfo { get; set; }

    ///<summary>
    /// Message ID of the last <a href="https://corefork.telegram.org/api/pin">pinned message</a>
    ///</summary>
    public int? PinnedMsgId { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/folders#peer-folders">Peer folder ID, for more info click here</a>
    ///</summary>
    public int? FolderId { get; set; }

    ///<summary>
    /// Group call information
    /// See <a href="https://corefork.telegram.org/type/InputGroupCall" />
    ///</summary>
    public MyTelegram.Schema.IInputGroupCall? Call { get; set; }

    ///<summary>
    /// Time-To-Live of messages sent by the current user to this chat
    ///</summary>
    public int? TtlPeriod { get; set; }

    ///<summary>
    /// When using <a href="https://corefork.telegram.org/method/phone.getGroupCallJoinAs">phone.getGroupCallJoinAs</a> to get a list of peers that can be used to join a group call, this field indicates the peer that should be selected by default.
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer? GroupcallDefaultJoinAs { get; set; }

    ///<summary>
    /// Emoji representing a specific chat theme
    ///</summary>
    public string? ThemeEmoticon { get; set; }

    ///<summary>
    /// Pending <a href="https://corefork.telegram.org/api/invites#join-requests">join requests »</a>
    ///</summary>
    public int? RequestsPending { get; set; }

    ///<summary>
    /// IDs of users who requested to join recently
    ///</summary>
    public TVector<long>? RecentRequesters { get; set; }

    ///<summary>
    /// Allowed <a href="https://corefork.telegram.org/api/reactions">message reactions »</a>
    /// See <a href="https://corefork.telegram.org/type/ChatReactions" />
    ///</summary>
    public MyTelegram.Schema.IChatReactions? AvailableReactions { get; set; }

    ///<summary>
    /// This flag may be used to impose a custom limit of unique reactions (i.e. a customizable version of <a href="https://corefork.telegram.org/api/config#reactions-uniq-max">appConfig.reactions_uniq_max</a>).
    ///</summary>
    public int? ReactionsLimit { get; set; }

    public void ComputeFlag()
    {
        if (CanSetUsername) { Flags = Flags.SetBit(7); }
        if (HasScheduled) { Flags = Flags.SetBit(8); }
        if (TranslationsDisabled) { Flags = Flags.SetBit(19); }
        if (ChatPhoto != null) { Flags = Flags.SetBit(2); }
        if (ExportedInvite != null) { Flags = Flags.SetBit(13); }
        if (BotInfo?.Count > 0) { Flags = Flags.SetBit(3); }
        if (/*PinnedMsgId != 0 && */PinnedMsgId.HasValue) { Flags = Flags.SetBit(6); }
        if (/*FolderId != 0 && */FolderId.HasValue) { Flags = Flags.SetBit(11); }
        if (Call != null) { Flags = Flags.SetBit(12); }
        if (/*TtlPeriod != 0 && */TtlPeriod.HasValue) { Flags = Flags.SetBit(14); }
        if (GroupcallDefaultJoinAs != null) { Flags = Flags.SetBit(15); }
        if (ThemeEmoticon != null) { Flags = Flags.SetBit(16); }
        if (/*RequestsPending != 0 && */RequestsPending.HasValue) { Flags = Flags.SetBit(17); }
        if (RecentRequesters?.Count > 0) { Flags = Flags.SetBit(17); }
        if (AvailableReactions != null) { Flags = Flags.SetBit(18); }
        if (/*ReactionsLimit != 0 && */ReactionsLimit.HasValue) { Flags = Flags.SetBit(20); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Id);
        writer.Write(About);
        writer.Write(Participants);
        if (Flags.IsBitSet(2)) { writer.Write(ChatPhoto); }
        writer.Write(NotifySettings);
        if (Flags.IsBitSet(13)) { writer.Write(ExportedInvite); }
        if (Flags.IsBitSet(3)) { writer.Write(BotInfo); }
        if (Flags.IsBitSet(6)) { writer.Write(PinnedMsgId.Value); }
        if (Flags.IsBitSet(11)) { writer.Write(FolderId.Value); }
        if (Flags.IsBitSet(12)) { writer.Write(Call); }
        if (Flags.IsBitSet(14)) { writer.Write(TtlPeriod.Value); }
        if (Flags.IsBitSet(15)) { writer.Write(GroupcallDefaultJoinAs); }
        if (Flags.IsBitSet(16)) { writer.Write(ThemeEmoticon); }
        if (Flags.IsBitSet(17)) { writer.Write(RequestsPending.Value); }
        if (Flags.IsBitSet(17)) { writer.Write(RecentRequesters); }
        if (Flags.IsBitSet(18)) { writer.Write(AvailableReactions); }
        if (Flags.IsBitSet(20)) { writer.Write(ReactionsLimit.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(7)) { CanSetUsername = true; }
        if (Flags.IsBitSet(8)) { HasScheduled = true; }
        if (Flags.IsBitSet(19)) { TranslationsDisabled = true; }
        Id = buffer.ReadInt64();
        About = buffer.ReadString();
        Participants = buffer.Read<MyTelegram.Schema.IChatParticipants>();
        if (Flags.IsBitSet(2)) { ChatPhoto = buffer.Read<MyTelegram.Schema.IPhoto>(); }
        NotifySettings = buffer.Read<MyTelegram.Schema.IPeerNotifySettings>();
        if (Flags.IsBitSet(13)) { ExportedInvite = buffer.Read<MyTelegram.Schema.IExportedChatInvite>(); }
        if (Flags.IsBitSet(3)) { BotInfo = buffer.Read<TVector<MyTelegram.Schema.IBotInfo>>(); }
        if (Flags.IsBitSet(6)) { PinnedMsgId = buffer.ReadInt32(); }
        if (Flags.IsBitSet(11)) { FolderId = buffer.ReadInt32(); }
        if (Flags.IsBitSet(12)) { Call = buffer.Read<MyTelegram.Schema.IInputGroupCall>(); }
        if (Flags.IsBitSet(14)) { TtlPeriod = buffer.ReadInt32(); }
        if (Flags.IsBitSet(15)) { GroupcallDefaultJoinAs = buffer.Read<MyTelegram.Schema.IPeer>(); }
        if (Flags.IsBitSet(16)) { ThemeEmoticon = buffer.ReadString(); }
        if (Flags.IsBitSet(17)) { RequestsPending = buffer.ReadInt32(); }
        if (Flags.IsBitSet(17)) { RecentRequesters = buffer.Read<TVector<long>>(); }
        if (Flags.IsBitSet(18)) { AvailableReactions = buffer.Read<MyTelegram.Schema.IChatReactions>(); }
        if (Flags.IsBitSet(20)) { ReactionsLimit = buffer.ReadInt32(); }
    }
}