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

// TopPeer represents TL type `topPeer#edcdc05b`.
// Top peer
//
// See https://core.telegram.org/constructor/topPeer for reference.
type TopPeer struct {
	// Peer
	Peer PeerClass
	// Rating as computed in top peer rating »¹
	//
	// Links:
	//  1) https://core.telegram.org/api/top-rating
	Rating float64
}

// TopPeerTypeID is TL type id of TopPeer.
const TopPeerTypeID = 0xedcdc05b

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

func ( *TopPeer) () bool {
	if  == nil {
		return true
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.Rating == 0) {
		return false
	}

	return true
}

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

// FillFrom fills TopPeer from given interface.
func ( *TopPeer) ( interface {
	() ( PeerClass)
	() ( float64)
}) {
	.Peer = .()
	.Rating = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *TopPeer) () tdp.Type {
	 := tdp.Type{
		Name: "topPeer",
		ID:   TopPeerTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Rating",
			SchemaName: "rating",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *TopPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode topPeer#edcdc05b as nil")
	}
	.PutID(TopPeerTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *TopPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode topPeer#edcdc05b as nil")
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode topPeer#edcdc05b: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode topPeer#edcdc05b: field peer: %w", )
	}
	.PutDouble(.Rating)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *TopPeer) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode topPeer#edcdc05b to nil")
	}
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode topPeer#edcdc05b: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Double()
		if  != nil {
			return fmt.Errorf("unable to decode topPeer#edcdc05b: field rating: %w", )
		}
		.Rating = 
	}
	return nil
}

// GetPeer returns value of Peer field.
func ( *TopPeer) () ( PeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

// GetRating returns value of Rating field.
func ( *TopPeer) () ( float64) {
	if  == nil {
		return
	}
	return .Rating
}