// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

// 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{}
)

// ChatParticipant represents TL type `chatParticipant#38e79fde`.
// Basic group¹ member (not usable by supergroups).
//
// Links:
//  1. https://core.telegram.org/api/channel#basic-groups
//
// See https://core.telegram.org/constructor/chatParticipant for reference.
type ChatParticipant struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Member user ID
	UserID int64
	// ID of the user that added the member to the group
	InviterID int64
	// Date added to the group
	Date int
	// The participant's tag »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/rank
	//
	// Use SetRank and GetRank helpers.
	Rank string
}

// ChatParticipantTypeID is TL type id of ChatParticipant.
const ChatParticipantTypeID = 0x38e79fde

// construct implements constructor of ChatParticipantClass.
func ( ChatParticipant) () ChatParticipantClass { return & }

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

	_ ChatParticipantClass = &ChatParticipant{}
)

func ( *ChatParticipant) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.UserID == 0) {
		return false
	}
	if !(.InviterID == 0) {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.Rank == "") {
		return false
	}

	return true
}

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

// FillFrom fills ChatParticipant from given interface.
func ( *ChatParticipant) ( interface {
	() ( int64)
	() ( int64)
	() ( int)
	() ( string,  bool)
}) {
	.UserID = .()
	.InviterID = .()
	.Date = .()
	if ,  := .();  {
		.Rank = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *ChatParticipant) () tdp.Type {
	 := tdp.Type{
		Name: "chatParticipant",
		ID:   ChatParticipantTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "InviterID",
			SchemaName: "inviter_id",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Rank",
			SchemaName: "rank",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *ChatParticipant) () {
	if !(.Rank == "") {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *ChatParticipant) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatParticipant#38e79fde as nil")
	}
	.PutID(ChatParticipantTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChatParticipant) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatParticipant#38e79fde as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode chatParticipant#38e79fde: field flags: %w", )
	}
	.PutLong(.UserID)
	.PutLong(.InviterID)
	.PutInt(.Date)
	if .Flags.Has(0) {
		.PutString(.Rank)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *ChatParticipant) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatParticipant#38e79fde to nil")
	}
	if  := .ConsumeID(ChatParticipantTypeID);  != nil {
		return fmt.Errorf("unable to decode chatParticipant#38e79fde: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ChatParticipant) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatParticipant#38e79fde to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode chatParticipant#38e79fde: field flags: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipant#38e79fde: field user_id: %w", )
		}
		.UserID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipant#38e79fde: field inviter_id: %w", )
		}
		.InviterID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipant#38e79fde: field date: %w", )
		}
		.Date = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipant#38e79fde: field rank: %w", )
		}
		.Rank = 
	}
	return nil
}

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

// GetInviterID returns value of InviterID field.
func ( *ChatParticipant) () ( int64) {
	if  == nil {
		return
	}
	return .InviterID
}

// GetDate returns value of Date field.
func ( *ChatParticipant) () ( int) {
	if  == nil {
		return
	}
	return .Date
}

// SetRank sets value of Rank conditional field.
func ( *ChatParticipant) ( string) {
	.Flags.Set(0)
	.Rank = 
}

// GetRank returns value of Rank conditional field and
// boolean which is true if field was set.
func ( *ChatParticipant) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Rank, true
}

// ChatParticipantCreator represents TL type `chatParticipantCreator#e1f867b8`.
// Represents the creator of the basic group »¹
//
// Links:
//  1. https://core.telegram.org/api/channel#basic-groups
//
// See https://core.telegram.org/constructor/chatParticipantCreator for reference.
type ChatParticipantCreator struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// ID of the user that created the group
	UserID int64
	// The participant's tag »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/rank
	//
	// Use SetRank and GetRank helpers.
	Rank string
}

// ChatParticipantCreatorTypeID is TL type id of ChatParticipantCreator.
const ChatParticipantCreatorTypeID = 0xe1f867b8

// construct implements constructor of ChatParticipantClass.
func ( ChatParticipantCreator) () ChatParticipantClass { return & }

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

	_ ChatParticipantClass = &ChatParticipantCreator{}
)

func ( *ChatParticipantCreator) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.UserID == 0) {
		return false
	}
	if !(.Rank == "") {
		return false
	}

	return true
}

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

// FillFrom fills ChatParticipantCreator from given interface.
func ( *ChatParticipantCreator) ( interface {
	() ( int64)
	() ( string,  bool)
}) {
	.UserID = .()
	if ,  := .();  {
		.Rank = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *ChatParticipantCreator) () tdp.Type {
	 := tdp.Type{
		Name: "chatParticipantCreator",
		ID:   ChatParticipantCreatorTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "Rank",
			SchemaName: "rank",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *ChatParticipantCreator) () {
	if !(.Rank == "") {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *ChatParticipantCreator) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatParticipantCreator#e1f867b8 as nil")
	}
	.PutID(ChatParticipantCreatorTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChatParticipantCreator) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatParticipantCreator#e1f867b8 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode chatParticipantCreator#e1f867b8: field flags: %w", )
	}
	.PutLong(.UserID)
	if .Flags.Has(0) {
		.PutString(.Rank)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *ChatParticipantCreator) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatParticipantCreator#e1f867b8 to nil")
	}
	if  := .ConsumeID(ChatParticipantCreatorTypeID);  != nil {
		return fmt.Errorf("unable to decode chatParticipantCreator#e1f867b8: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ChatParticipantCreator) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatParticipantCreator#e1f867b8 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode chatParticipantCreator#e1f867b8: field flags: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipantCreator#e1f867b8: field user_id: %w", )
		}
		.UserID = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipantCreator#e1f867b8: field rank: %w", )
		}
		.Rank = 
	}
	return nil
}

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

// SetRank sets value of Rank conditional field.
func ( *ChatParticipantCreator) ( string) {
	.Flags.Set(0)
	.Rank = 
}

// GetRank returns value of Rank conditional field and
// boolean which is true if field was set.
func ( *ChatParticipantCreator) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Rank, true
}

// ChatParticipantAdmin represents TL type `chatParticipantAdmin#360d5d2`.
// Basic group¹ admin (not usable by supergroups).
//
// Links:
//  1. https://core.telegram.org/api/channel#basic-groups
//
// See https://core.telegram.org/constructor/chatParticipantAdmin for reference.
type ChatParticipantAdmin struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// ID of a group member that is admin
	UserID int64
	// ID of the user that added the member to the group
	InviterID int64
	// Date when the user was added
	Date int
	// The participant's tag »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/rank
	//
	// Use SetRank and GetRank helpers.
	Rank string
}

// ChatParticipantAdminTypeID is TL type id of ChatParticipantAdmin.
const ChatParticipantAdminTypeID = 0x360d5d2

// construct implements constructor of ChatParticipantClass.
func ( ChatParticipantAdmin) () ChatParticipantClass { return & }

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

	_ ChatParticipantClass = &ChatParticipantAdmin{}
)

func ( *ChatParticipantAdmin) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.UserID == 0) {
		return false
	}
	if !(.InviterID == 0) {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.Rank == "") {
		return false
	}

	return true
}

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

// FillFrom fills ChatParticipantAdmin from given interface.
func ( *ChatParticipantAdmin) ( interface {
	() ( int64)
	() ( int64)
	() ( int)
	() ( string,  bool)
}) {
	.UserID = .()
	.InviterID = .()
	.Date = .()
	if ,  := .();  {
		.Rank = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *ChatParticipantAdmin) () tdp.Type {
	 := tdp.Type{
		Name: "chatParticipantAdmin",
		ID:   ChatParticipantAdminTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "UserID",
			SchemaName: "user_id",
		},
		{
			Name:       "InviterID",
			SchemaName: "inviter_id",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Rank",
			SchemaName: "rank",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *ChatParticipantAdmin) () {
	if !(.Rank == "") {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *ChatParticipantAdmin) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatParticipantAdmin#360d5d2 as nil")
	}
	.PutID(ChatParticipantAdminTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChatParticipantAdmin) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatParticipantAdmin#360d5d2 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode chatParticipantAdmin#360d5d2: field flags: %w", )
	}
	.PutLong(.UserID)
	.PutLong(.InviterID)
	.PutInt(.Date)
	if .Flags.Has(0) {
		.PutString(.Rank)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *ChatParticipantAdmin) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatParticipantAdmin#360d5d2 to nil")
	}
	if  := .ConsumeID(ChatParticipantAdminTypeID);  != nil {
		return fmt.Errorf("unable to decode chatParticipantAdmin#360d5d2: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *ChatParticipantAdmin) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatParticipantAdmin#360d5d2 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode chatParticipantAdmin#360d5d2: field flags: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipantAdmin#360d5d2: field user_id: %w", )
		}
		.UserID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipantAdmin#360d5d2: field inviter_id: %w", )
		}
		.InviterID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipantAdmin#360d5d2: field date: %w", )
		}
		.Date = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode chatParticipantAdmin#360d5d2: field rank: %w", )
		}
		.Rank = 
	}
	return nil
}

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

// GetInviterID returns value of InviterID field.
func ( *ChatParticipantAdmin) () ( int64) {
	if  == nil {
		return
	}
	return .InviterID
}

// GetDate returns value of Date field.
func ( *ChatParticipantAdmin) () ( int) {
	if  == nil {
		return
	}
	return .Date
}

// SetRank sets value of Rank conditional field.
func ( *ChatParticipantAdmin) ( string) {
	.Flags.Set(0)
	.Rank = 
}

// GetRank returns value of Rank conditional field and
// boolean which is true if field was set.
func ( *ChatParticipantAdmin) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Rank, true
}

// ChatParticipantClassName is schema name of ChatParticipantClass.
const ChatParticipantClassName = "ChatParticipant"

// ChatParticipantClass represents ChatParticipant generic type.
//
// See https://core.telegram.org/type/ChatParticipant for reference.
//
// Constructors:
//   - [ChatParticipant]
//   - [ChatParticipantCreator]
//   - [ChatParticipantAdmin]
//
// Example:
//
//	g, err := tg.DecodeChatParticipant(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.ChatParticipant: // chatParticipant#38e79fde
//	case *tg.ChatParticipantCreator: // chatParticipantCreator#e1f867b8
//	case *tg.ChatParticipantAdmin: // chatParticipantAdmin#360d5d2
//	default: panic(v)
//	}
type ChatParticipantClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ChatParticipantClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// Member user ID
	GetUserID() (value int64)

	// The participant's tag »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/rank
	GetRank() (value string, ok bool)
}

// DecodeChatParticipant implements binary de-serialization for ChatParticipantClass.
func ( *bin.Buffer) (ChatParticipantClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case ChatParticipantTypeID:
		// Decoding chatParticipant#38e79fde.
		 := ChatParticipant{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ChatParticipantClass: %w", )
		}
		return &, nil
	case ChatParticipantCreatorTypeID:
		// Decoding chatParticipantCreator#e1f867b8.
		 := ChatParticipantCreator{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ChatParticipantClass: %w", )
		}
		return &, nil
	case ChatParticipantAdminTypeID:
		// Decoding chatParticipantAdmin#360d5d2.
		 := ChatParticipantAdmin{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ChatParticipantClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode ChatParticipantClass: %w", bin.NewUnexpectedID())
	}
}

// ChatParticipant boxes the ChatParticipantClass providing a helper.
type ChatParticipantBox struct {
	ChatParticipant ChatParticipantClass
}

// Decode implements bin.Decoder for ChatParticipantBox.
func ( *ChatParticipantBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode ChatParticipantBox to nil")
	}
	,  := DecodeChatParticipant()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.ChatParticipant = 
	return nil
}

// Encode implements bin.Encode for ChatParticipantBox.
func ( *ChatParticipantBox) ( *bin.Buffer) error {
	if  == nil || .ChatParticipant == nil {
		return fmt.Errorf("unable to encode ChatParticipantClass as nil")
	}
	return .ChatParticipant.Encode()
}