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

// HelpCountry represents TL type `help.country#c3878e23`.
// Name, ISO code, localized name and phone codes/patterns of a specific country
//
// See https://core.telegram.org/constructor/help.country for reference.
type HelpCountry struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this country should not be shown in the list
	Hidden bool
	// ISO code of country
	ISO2 string
	// Name of the country in the country's language
	DefaultName string
	// Name of the country in the user's language, if different from the original name
	//
	// Use SetName and GetName helpers.
	Name string
	// Phone codes/patterns
	CountryCodes []HelpCountryCode
}

// HelpCountryTypeID is TL type id of HelpCountry.
const HelpCountryTypeID = 0xc3878e23

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

func ( *HelpCountry) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Hidden == false) {
		return false
	}
	if !(.ISO2 == "") {
		return false
	}
	if !(.DefaultName == "") {
		return false
	}
	if !(.Name == "") {
		return false
	}
	if !(.CountryCodes == nil) {
		return false
	}

	return true
}

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

// FillFrom fills HelpCountry from given interface.
func ( *HelpCountry) ( interface {
	() ( bool)
	() ( string)
	() ( string)
	() ( string,  bool)
	() ( []HelpCountryCode)
}) {
	.Hidden = .()
	.ISO2 = .()
	.DefaultName = .()
	if ,  := .();  {
		.Name = 
	}

	.CountryCodes = .()
}

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

// TypeName returns name of type in TL schema.
func (*HelpCountry) () string {
	return "help.country"
}

// TypeInfo returns info about TL type.
func ( *HelpCountry) () tdp.Type {
	 := tdp.Type{
		Name: "help.country",
		ID:   HelpCountryTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Hidden",
			SchemaName: "hidden",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "ISO2",
			SchemaName: "iso2",
		},
		{
			Name:       "DefaultName",
			SchemaName: "default_name",
		},
		{
			Name:       "Name",
			SchemaName: "name",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "CountryCodes",
			SchemaName: "country_codes",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *HelpCountry) () {
	if !(.Hidden == false) {
		.Flags.Set(0)
	}
	if !(.Name == "") {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *HelpCountry) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.country#c3878e23 as nil")
	}
	.PutID(HelpCountryTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *HelpCountry) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.country#c3878e23 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode help.country#c3878e23: field flags: %w", )
	}
	.PutString(.ISO2)
	.PutString(.DefaultName)
	if .Flags.Has(1) {
		.PutString(.Name)
	}
	.PutVectorHeader(len(.CountryCodes))
	for ,  := range .CountryCodes {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode help.country#c3878e23: field country_codes element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *HelpCountry) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode help.country#c3878e23 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode help.country#c3878e23: field flags: %w", )
		}
	}
	.Hidden = .Flags.Has(0)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode help.country#c3878e23: field iso2: %w", )
		}
		.ISO2 = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode help.country#c3878e23: field default_name: %w", )
		}
		.DefaultName = 
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode help.country#c3878e23: field name: %w", )
		}
		.Name = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode help.country#c3878e23: field country_codes: %w", )
		}

		if  > 0 {
			.CountryCodes = make([]HelpCountryCode, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  HelpCountryCode
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode help.country#c3878e23: field country_codes: %w", )
			}
			.CountryCodes = append(.CountryCodes, )
		}
	}
	return nil
}

// SetHidden sets value of Hidden conditional field.
func ( *HelpCountry) ( bool) {
	if  {
		.Flags.Set(0)
		.Hidden = true
	} else {
		.Flags.Unset(0)
		.Hidden = false
	}
}

// GetHidden returns value of Hidden conditional field.
func ( *HelpCountry) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetISO2 returns value of ISO2 field.
func ( *HelpCountry) () ( string) {
	if  == nil {
		return
	}
	return .ISO2
}

// GetDefaultName returns value of DefaultName field.
func ( *HelpCountry) () ( string) {
	if  == nil {
		return
	}
	return .DefaultName
}

// SetName sets value of Name conditional field.
func ( *HelpCountry) ( string) {
	.Flags.Set(1)
	.Name = 
}

// GetName returns value of Name conditional field and
// boolean which is true if field was set.
func ( *HelpCountry) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Name, true
}

// GetCountryCodes returns value of CountryCodes field.
func ( *HelpCountry) () ( []HelpCountryCode) {
	if  == nil {
		return
	}
	return .CountryCodes
}