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

// MessageReactor represents TL type `messageReactor#4ba3a95a`.
// Info about a user in the paid Star reactions leaderboard¹ for a message.
//
// Links:
//  1. https://core.telegram.org/api/reactions#paid-reactions
//
// See https://core.telegram.org/constructor/messageReactor for reference.
type MessageReactor struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, the reactor is one of the most active reactors; may be unset if the reactor is
	// the current user.
	Top bool
	// If set, this reactor is the current user.
	My bool
	// If set, the reactor is anonymous.
	Anonymous bool
	// Identifier of the peer that reacted: may be unset for anonymous reactors different
	// from the current user (i.e. if the current user sent an anonymous reaction anonymous
	// will be set but this field will also be set).
	//
	// Use SetPeerID and GetPeerID helpers.
	PeerID PeerClass
	// The number of sent Telegram Stars.
	Count int
}

// MessageReactorTypeID is TL type id of MessageReactor.
const MessageReactorTypeID = 0x4ba3a95a

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

func ( *MessageReactor) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Top == false) {
		return false
	}
	if !(.My == false) {
		return false
	}
	if !(.Anonymous == false) {
		return false
	}
	if !(.PeerID == nil) {
		return false
	}
	if !(.Count == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessageReactor from given interface.
func ( *MessageReactor) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( PeerClass,  bool)
	() ( int)
}) {
	.Top = .()
	.My = .()
	.Anonymous = .()
	if ,  := .();  {
		.PeerID = 
	}

	.Count = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessageReactor) () tdp.Type {
	 := tdp.Type{
		Name: "messageReactor",
		ID:   MessageReactorTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Top",
			SchemaName: "top",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "My",
			SchemaName: "my",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Anonymous",
			SchemaName: "anonymous",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "PeerID",
			SchemaName: "peer_id",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Count",
			SchemaName: "count",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessageReactor) () {
	if !(.Top == false) {
		.Flags.Set(0)
	}
	if !(.My == false) {
		.Flags.Set(1)
	}
	if !(.Anonymous == false) {
		.Flags.Set(2)
	}
	if !(.PeerID == nil) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *MessageReactor) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageReactor#4ba3a95a as nil")
	}
	.PutID(MessageReactorTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessageReactor) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageReactor#4ba3a95a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messageReactor#4ba3a95a: field flags: %w", )
	}
	if .Flags.Has(3) {
		if .PeerID == nil {
			return fmt.Errorf("unable to encode messageReactor#4ba3a95a: field peer_id is nil")
		}
		if  := .PeerID.Encode();  != nil {
			return fmt.Errorf("unable to encode messageReactor#4ba3a95a: field peer_id: %w", )
		}
	}
	.PutInt(.Count)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessageReactor) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messageReactor#4ba3a95a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messageReactor#4ba3a95a: field flags: %w", )
		}
	}
	.Top = .Flags.Has(0)
	.My = .Flags.Has(1)
	.Anonymous = .Flags.Has(2)
	if .Flags.Has(3) {
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode messageReactor#4ba3a95a: field peer_id: %w", )
		}
		.PeerID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageReactor#4ba3a95a: field count: %w", )
		}
		.Count = 
	}
	return nil
}

// SetTop sets value of Top conditional field.
func ( *MessageReactor) ( bool) {
	if  {
		.Flags.Set(0)
		.Top = true
	} else {
		.Flags.Unset(0)
		.Top = false
	}
}

// GetTop returns value of Top conditional field.
func ( *MessageReactor) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetMy sets value of My conditional field.
func ( *MessageReactor) ( bool) {
	if  {
		.Flags.Set(1)
		.My = true
	} else {
		.Flags.Unset(1)
		.My = false
	}
}

// GetMy returns value of My conditional field.
func ( *MessageReactor) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetAnonymous sets value of Anonymous conditional field.
func ( *MessageReactor) ( bool) {
	if  {
		.Flags.Set(2)
		.Anonymous = true
	} else {
		.Flags.Unset(2)
		.Anonymous = false
	}
}

// GetAnonymous returns value of Anonymous conditional field.
func ( *MessageReactor) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetPeerID sets value of PeerID conditional field.
func ( *MessageReactor) ( PeerClass) {
	.Flags.Set(3)
	.PeerID = 
}

// GetPeerID returns value of PeerID conditional field and
// boolean which is true if field was set.
func ( *MessageReactor) () ( PeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .PeerID, true
}

// GetCount returns value of Count field.
func ( *MessageReactor) () ( int) {
	if  == nil {
		return
	}
	return .Count
}