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

// PeerColor represents TL type `peerColor#b54b5acf`.
// Represents a color palette »¹.
//
// Links:
//  1. https://core.telegram.org/api/colors
//
// See https://core.telegram.org/constructor/peerColor for reference.
type PeerColor struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Color palette ID, see here »¹ for more info.
	//
	// Links:
	//  1) https://core.telegram.org/api/colors
	//
	// Use SetColor and GetColor helpers.
	Color int
	// Custom emoji ID¹ used to generate the pattern.
	//
	// Links:
	//  1) https://core.telegram.org/api/custom-emoji
	//
	// Use SetBackgroundEmojiID and GetBackgroundEmojiID helpers.
	BackgroundEmojiID int64
}

// PeerColorTypeID is TL type id of PeerColor.
const PeerColorTypeID = 0xb54b5acf

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

func ( *PeerColor) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Color == 0) {
		return false
	}
	if !(.BackgroundEmojiID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PeerColor from given interface.
func ( *PeerColor) ( interface {
	() ( int,  bool)
	() ( int64,  bool)
}) {
	if ,  := .();  {
		.Color = 
	}

	if ,  := .();  {
		.BackgroundEmojiID = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *PeerColor) () tdp.Type {
	 := tdp.Type{
		Name: "peerColor",
		ID:   PeerColorTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Color",
			SchemaName: "color",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "BackgroundEmojiID",
			SchemaName: "background_emoji_id",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PeerColor) () {
	if !(.Color == 0) {
		.Flags.Set(0)
	}
	if !(.BackgroundEmojiID == 0) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *PeerColor) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerColor#b54b5acf as nil")
	}
	.PutID(PeerColorTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PeerColor) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode peerColor#b54b5acf as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode peerColor#b54b5acf: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutInt(.Color)
	}
	if .Flags.Has(1) {
		.PutLong(.BackgroundEmojiID)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PeerColor) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode peerColor#b54b5acf to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode peerColor#b54b5acf: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode peerColor#b54b5acf: field color: %w", )
		}
		.Color = 
	}
	if .Flags.Has(1) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode peerColor#b54b5acf: field background_emoji_id: %w", )
		}
		.BackgroundEmojiID = 
	}
	return nil
}

// SetColor sets value of Color conditional field.
func ( *PeerColor) ( int) {
	.Flags.Set(0)
	.Color = 
}

// GetColor returns value of Color conditional field and
// boolean which is true if field was set.
func ( *PeerColor) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Color, true
}

// SetBackgroundEmojiID sets value of BackgroundEmojiID conditional field.
func ( *PeerColor) ( int64) {
	.Flags.Set(1)
	.BackgroundEmojiID = 
}

// GetBackgroundEmojiID returns value of BackgroundEmojiID conditional field and
// boolean which is true if field was set.
func ( *PeerColor) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .BackgroundEmojiID, true
}