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

namespace MyTelegram.Schema;

///<summary>
/// Chat invite info
/// See <a href="https://corefork.telegram.org/constructor/chatInvite" />
///</summary>
[TlObject(0x5c9d3702)]
public sealed class TChatInvite : IChatInvite
{
    public uint ConstructorId => 0x5c9d3702;
    ///<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 this is a <a href="https://corefork.telegram.org/api/channel">channel/supergroup</a> or a <a href="https://corefork.telegram.org/api/channel">normal group</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Channel { get; set; }

    ///<summary>
    /// Whether this is a <a href="https://corefork.telegram.org/api/channel">channel</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Broadcast { get; set; }

    ///<summary>
    /// Whether this is a public <a href="https://corefork.telegram.org/api/channel">channel/supergroup</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Public { get; set; }

    ///<summary>
    /// Whether this is a <a href="https://corefork.telegram.org/api/channel">supergroup</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Megagroup { get; set; }

    ///<summary>
    /// Whether the <a href="https://corefork.telegram.org/api/invites#join-requests">join request »</a> must be first approved by an administrator
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool RequestNeeded { get; set; }

    ///<summary>
    /// Is this chat or channel verified by Telegram?
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Verified { get; set; }

    ///<summary>
    /// This chat is probably a scam
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Scam { get; set; }

    ///<summary>
    /// If set, this chat was reported by many users as a fake or scam: be careful when interacting with it.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Fake { get; set; }

    ///<summary>
    /// If set, indicates that the user has already paid for the associated <a href="https://corefork.telegram.org/api/stars#star-subscriptions">Telegram Star subscriptions »</a> and it hasn't expired yet, so they may re-join the channel using <a href="https://corefork.telegram.org/method/messages.importChatInvite">messages.importChatInvite</a> without repeating the payment.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool CanRefulfillSubscription { get; set; }

    ///<summary>
    /// Chat/supergroup/channel title
    ///</summary>
    public string Title { get; set; }

    ///<summary>
    /// Description of the group of channel
    ///</summary>
    public string? About { get; set; }

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

    ///<summary>
    /// Participant count
    ///</summary>
    public int ParticipantsCount { get; set; }

    ///<summary>
    /// A few of the participants that are in the group
    ///</summary>
    public TVector<MyTelegram.Schema.IUser>? Participants { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/colors">Profile color palette ID</a>
    ///</summary>
    public int Color { get; set; }

    ///<summary>
    /// For <a href="https://corefork.telegram.org/api/stars#star-subscriptions">Telegram Star subscriptions »</a>, contains the pricing of the subscription the user must activate to join the private channel.
    /// See <a href="https://corefork.telegram.org/type/StarsSubscriptionPricing" />
    ///</summary>
    public MyTelegram.Schema.IStarsSubscriptionPricing? SubscriptionPricing { get; set; }

    ///<summary>
    /// For <a href="https://corefork.telegram.org/api/stars#star-subscriptions">Telegram Star subscriptions »</a>, the ID of the payment form for the subscription.
    ///</summary>
    public long? SubscriptionFormId { get; set; }
    public MyTelegram.Schema.IBotVerification? BotVerification { get; set; }

    public void ComputeFlag()
    {
        if (Channel) { Flags = Flags.SetBit(0); }
        if (Broadcast) { Flags = Flags.SetBit(1); }
        if (Public) { Flags = Flags.SetBit(2); }
        if (Megagroup) { Flags = Flags.SetBit(3); }
        if (RequestNeeded) { Flags = Flags.SetBit(6); }
        if (Verified) { Flags = Flags.SetBit(7); }
        if (Scam) { Flags = Flags.SetBit(8); }
        if (Fake) { Flags = Flags.SetBit(9); }
        if (CanRefulfillSubscription) { Flags = Flags.SetBit(11); }
        if (About != null) { Flags = Flags.SetBit(5); }
        if (Participants?.Count > 0) { Flags = Flags.SetBit(4); }
        if (SubscriptionPricing != null) { Flags = Flags.SetBit(10); }
        if (/*SubscriptionFormId != 0 &&*/ SubscriptionFormId.HasValue) { Flags = Flags.SetBit(12); }
        if (BotVerification != null) { Flags = Flags.SetBit(13); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Title);
        if (Flags.IsBitSet(5)) { writer.Write(About); }
        writer.Write(Photo);
        writer.Write(ParticipantsCount);
        if (Flags.IsBitSet(4)) { writer.Write(Participants); }
        writer.Write(Color);
        if (Flags.IsBitSet(10)) { writer.Write(SubscriptionPricing); }
        if (Flags.IsBitSet(12)) { writer.Write(SubscriptionFormId.Value); }
        if (Flags.IsBitSet(13)) { writer.Write(BotVerification); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Channel = true; }
        if (Flags.IsBitSet(1)) { Broadcast = true; }
        if (Flags.IsBitSet(2)) { Public = true; }
        if (Flags.IsBitSet(3)) { Megagroup = true; }
        if (Flags.IsBitSet(6)) { RequestNeeded = true; }
        if (Flags.IsBitSet(7)) { Verified = true; }
        if (Flags.IsBitSet(8)) { Scam = true; }
        if (Flags.IsBitSet(9)) { Fake = true; }
        if (Flags.IsBitSet(11)) { CanRefulfillSubscription = true; }
        Title = buffer.ReadString();
        if (Flags.IsBitSet(5)) { About = buffer.ReadString(); }
        Photo = buffer.Read<MyTelegram.Schema.IPhoto>();
        ParticipantsCount = buffer.ReadInt32();
        if (Flags.IsBitSet(4)) { Participants = buffer.Read<TVector<MyTelegram.Schema.IUser>>(); }
        Color = buffer.ReadInt32();
        if (Flags.IsBitSet(10)) { SubscriptionPricing = buffer.Read<MyTelegram.Schema.IStarsSubscriptionPricing>(); }
        if (Flags.IsBitSet(12)) { SubscriptionFormId = buffer.ReadInt64(); }
        if (Flags.IsBitSet(13)) { BotVerification = buffer.Read<MyTelegram.Schema.IBotVerification>(); }
    }
}