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

// StarsRating represents TL type `starsRating#1b0e4f07`.
// Represents the profile's star rating, see here »¹ for more info.
//
// Links:
//  1. https://core.telegram.org/api/stars#star-rating
//
// See https://core.telegram.org/constructor/starsRating for reference.
type StarsRating struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// The current level, may be negative.
	Level int
	// The numerical value of the rating required for the current level.
	CurrentLevelStars int64
	// Numerical value of the current rating.
	Stars int64
	// The numerical value of the rating required for the next level.
	//
	// Use SetNextLevelStars and GetNextLevelStars helpers.
	NextLevelStars int64
}

// StarsRatingTypeID is TL type id of StarsRating.
const StarsRatingTypeID = 0x1b0e4f07

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

func ( *StarsRating) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Level == 0) {
		return false
	}
	if !(.CurrentLevelStars == 0) {
		return false
	}
	if !(.Stars == 0) {
		return false
	}
	if !(.NextLevelStars == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarsRating from given interface.
func ( *StarsRating) ( interface {
	() ( int)
	() ( int64)
	() ( int64)
	() ( int64,  bool)
}) {
	.Level = .()
	.CurrentLevelStars = .()
	.Stars = .()
	if ,  := .();  {
		.NextLevelStars = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *StarsRating) () tdp.Type {
	 := tdp.Type{
		Name: "starsRating",
		ID:   StarsRatingTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Level",
			SchemaName: "level",
		},
		{
			Name:       "CurrentLevelStars",
			SchemaName: "current_level_stars",
		},
		{
			Name:       "Stars",
			SchemaName: "stars",
		},
		{
			Name:       "NextLevelStars",
			SchemaName: "next_level_stars",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *StarsRating) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsRating#1b0e4f07 as nil")
	}
	.PutID(StarsRatingTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarsRating) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsRating#1b0e4f07 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode starsRating#1b0e4f07: field flags: %w", )
	}
	.PutInt(.Level)
	.PutLong(.CurrentLevelStars)
	.PutLong(.Stars)
	if .Flags.Has(0) {
		.PutLong(.NextLevelStars)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StarsRating) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starsRating#1b0e4f07 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode starsRating#1b0e4f07: field flags: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starsRating#1b0e4f07: field level: %w", )
		}
		.Level = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starsRating#1b0e4f07: field current_level_stars: %w", )
		}
		.CurrentLevelStars = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starsRating#1b0e4f07: field stars: %w", )
		}
		.Stars = 
	}
	if .Flags.Has(0) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starsRating#1b0e4f07: field next_level_stars: %w", )
		}
		.NextLevelStars = 
	}
	return nil
}

// GetLevel returns value of Level field.
func ( *StarsRating) () ( int) {
	if  == nil {
		return
	}
	return .Level
}

// GetCurrentLevelStars returns value of CurrentLevelStars field.
func ( *StarsRating) () ( int64) {
	if  == nil {
		return
	}
	return .CurrentLevelStars
}

// GetStars returns value of Stars field.
func ( *StarsRating) () ( int64) {
	if  == nil {
		return
	}
	return .Stars
}

// SetNextLevelStars sets value of NextLevelStars conditional field.
func ( *StarsRating) ( int64) {
	.Flags.Set(0)
	.NextLevelStars = 
}

// GetNextLevelStars returns value of NextLevelStars conditional field and
// boolean which is true if field was set.
func ( *StarsRating) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .NextLevelStars, true
}