// Code generated by gotdgen, DO NOT EDIT.

package tdapi

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

// No-op definition for keeping imports.
var (
	_ = bin.Buffer{}
	_ = context.Background()
	_ = fmt.Stringer(nil)
	_ = strings.Builder{}
	_ = errors.Is
	_ = multierr.AppendInto
	_ = sort.Ints
	_ = tdp.Format
	_ = tgerr.Error{}
	_ = tdjson.Encoder{}
)

// ChatInviteLinkCount represents TL type `chatInviteLinkCount#c3158796`.
type ChatInviteLinkCount struct {
	// Administrator's user identifier
	UserID int64
	// Number of active invite links
	InviteLinkCount int32
	// Number of revoked invite links
	RevokedInviteLinkCount int32
}

// ChatInviteLinkCountTypeID is TL type id of ChatInviteLinkCount.
const ChatInviteLinkCountTypeID = 0xc3158796

// Ensuring interfaces in compile-time for ChatInviteLinkCount.
var (
	_ bin.Encoder     = &ChatInviteLinkCount{}
	_ bin.Decoder     = &ChatInviteLinkCount{}
	_ bin.BareEncoder = &ChatInviteLinkCount{}
	_ bin.BareDecoder = &ChatInviteLinkCount{}
)

func (c *ChatInviteLinkCount) Zero() bool {
	if c == nil {
		return true
	}
	if !(c.UserID == 0) {
		return false
	}
	if !(c.InviteLinkCount == 0) {
		return false
	}
	if !(c.RevokedInviteLinkCount == 0) {
		return false
	}

	return true
}

// String implements fmt.Stringer.
func (c *ChatInviteLinkCount) String() string {
	if c == nil {
		return "ChatInviteLinkCount(nil)"
	}
	type Alias ChatInviteLinkCount
	return fmt.Sprintf("ChatInviteLinkCount%+v", Alias(*c))
}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*ChatInviteLinkCount) TypeID() uint32 {
	return ChatInviteLinkCountTypeID
}

// TypeName returns name of type in TL schema.
func (*ChatInviteLinkCount) TypeName() string {
	return "chatInviteLinkCount"
}

// TypeInfo returns info about TL type.
func (c *ChatInviteLinkCount) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "chatInviteLinkCount",
		ID:   ChatInviteLinkCountTypeID,
	}
	if c == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "InviteLinkCount",
			SchemaName: "invite_link_count",
		},
		{
			Name:       "RevokedInviteLinkCount",
			SchemaName: "revoked_invite_link_count",
		},
	}
	return typ
}

// Encode implements bin.Encoder.
func (c *ChatInviteLinkCount) Encode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode chatInviteLinkCount#c3158796 as nil")
	}
	b.PutID(ChatInviteLinkCountTypeID)
	return c.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (c *ChatInviteLinkCount) EncodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't encode chatInviteLinkCount#c3158796 as nil")
	}
	b.PutInt53(c.UserID)
	b.PutInt32(c.InviteLinkCount)
	b.PutInt32(c.RevokedInviteLinkCount)
	return nil
}

// Decode implements bin.Decoder.
func (c *ChatInviteLinkCount) Decode(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode chatInviteLinkCount#c3158796 to nil")
	}
	if err := b.ConsumeID(ChatInviteLinkCountTypeID); err != nil {
		return fmt.Errorf("unable to decode chatInviteLinkCount#c3158796: %w", err)
	}
	return c.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (c *ChatInviteLinkCount) DecodeBare(b *bin.Buffer) error {
	if c == nil {
		return fmt.Errorf("can't decode chatInviteLinkCount#c3158796 to nil")
	}
	{
		value, err := b.Int53()
		if err != nil {
			return fmt.Errorf("unable to decode chatInviteLinkCount#c3158796: field user_id: %w", err)
		}
		c.UserID = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode chatInviteLinkCount#c3158796: field invite_link_count: %w", err)
		}
		c.InviteLinkCount = value
	}
	{
		value, err := b.Int32()
		if err != nil {
			return fmt.Errorf("unable to decode chatInviteLinkCount#c3158796: field revoked_invite_link_count: %w", err)
		}
		c.RevokedInviteLinkCount = value
	}
	return nil
}

// EncodeTDLibJSON implements tdjson.TDLibEncoder.
func (c *ChatInviteLinkCount) EncodeTDLibJSON(b tdjson.Encoder) error {
	if c == nil {
		return fmt.Errorf("can't encode chatInviteLinkCount#c3158796 as nil")
	}
	b.ObjStart()
	b.PutID("chatInviteLinkCount")
	b.Comma()
	b.FieldStart("user_id")
	b.PutInt53(c.UserID)
	b.Comma()
	b.FieldStart("invite_link_count")
	b.PutInt32(c.InviteLinkCount)
	b.Comma()
	b.FieldStart("revoked_invite_link_count")
	b.PutInt32(c.RevokedInviteLinkCount)
	b.Comma()
	b.StripComma()
	b.ObjEnd()
	return nil
}

// DecodeTDLibJSON implements tdjson.TDLibDecoder.
func (c *ChatInviteLinkCount) DecodeTDLibJSON(b tdjson.Decoder) error {
	if c == nil {
		return fmt.Errorf("can't decode chatInviteLinkCount#c3158796 to nil")
	}

	return b.Obj(func(b tdjson.Decoder, key []byte) error {
		switch string(key) {
		case tdjson.TypeField:
			if err := b.ConsumeID("chatInviteLinkCount"); err != nil {
				return fmt.Errorf("unable to decode chatInviteLinkCount#c3158796: %w", err)
			}
		case "user_id":
			value, err := b.Int53()
			if err != nil {
				return fmt.Errorf("unable to decode chatInviteLinkCount#c3158796: field user_id: %w", err)
			}
			c.UserID = value
		case "invite_link_count":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode chatInviteLinkCount#c3158796: field invite_link_count: %w", err)
			}
			c.InviteLinkCount = value
		case "revoked_invite_link_count":
			value, err := b.Int32()
			if err != nil {
				return fmt.Errorf("unable to decode chatInviteLinkCount#c3158796: field revoked_invite_link_count: %w", err)
			}
			c.RevokedInviteLinkCount = value
		default:
			return b.Skip()
		}
		return nil
	})
}

// GetUserID returns value of UserID field.
func (c *ChatInviteLinkCount) GetUserID() (value int64) {
	if c == nil {
		return
	}
	return c.UserID
}

// GetInviteLinkCount returns value of InviteLinkCount field.
func (c *ChatInviteLinkCount) GetInviteLinkCount() (value int32) {
	if c == nil {
		return
	}
	return c.InviteLinkCount
}

// GetRevokedInviteLinkCount returns value of RevokedInviteLinkCount field.
func (c *ChatInviteLinkCount) GetRevokedInviteLinkCount() (value int32) {
	if c == nil {
		return
	}
	return c.RevokedInviteLinkCount
}
