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

// HelpCountryCode represents TL type `help.countryCode#4203c5ef`.
// Country code and phone number pattern of a specific country
//
// See https://core.telegram.org/constructor/help.countryCode for reference.
type HelpCountryCode struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// ISO country code
	CountryCode string
	// Possible phone prefixes
	//
	// Use SetPrefixes and GetPrefixes helpers.
	Prefixes []string
	// Phone patterns: for example, XXX XXX XXX
	//
	// Use SetPatterns and GetPatterns helpers.
	Patterns []string
}

// HelpCountryCodeTypeID is TL type id of HelpCountryCode.
const HelpCountryCodeTypeID = 0x4203c5ef

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

func ( *HelpCountryCode) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.CountryCode == "") {
		return false
	}
	if !(.Prefixes == nil) {
		return false
	}
	if !(.Patterns == nil) {
		return false
	}

	return true
}

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

// FillFrom fills HelpCountryCode from given interface.
func ( *HelpCountryCode) ( interface {
	() ( string)
	() ( []string,  bool)
	() ( []string,  bool)
}) {
	.CountryCode = .()
	if ,  := .();  {
		.Prefixes = 
	}

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

}

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

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

// TypeInfo returns info about TL type.
func ( *HelpCountryCode) () tdp.Type {
	 := tdp.Type{
		Name: "help.countryCode",
		ID:   HelpCountryCodeTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "CountryCode",
			SchemaName: "country_code",
		},
		{
			Name:       "Prefixes",
			SchemaName: "prefixes",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Patterns",
			SchemaName: "patterns",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *HelpCountryCode) () {
	if !(.Prefixes == nil) {
		.Flags.Set(0)
	}
	if !(.Patterns == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *HelpCountryCode) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.countryCode#4203c5ef as nil")
	}
	.PutID(HelpCountryCodeTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *HelpCountryCode) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.countryCode#4203c5ef as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode help.countryCode#4203c5ef: field flags: %w", )
	}
	.PutString(.CountryCode)
	if .Flags.Has(0) {
		.PutVectorHeader(len(.Prefixes))
		for ,  := range .Prefixes {
			.PutString()
		}
	}
	if .Flags.Has(1) {
		.PutVectorHeader(len(.Patterns))
		for ,  := range .Patterns {
			.PutString()
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *HelpCountryCode) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode help.countryCode#4203c5ef to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode help.countryCode#4203c5ef: field flags: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode help.countryCode#4203c5ef: field country_code: %w", )
		}
		.CountryCode = 
	}
	if .Flags.Has(0) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode help.countryCode#4203c5ef: field prefixes: %w", )
		}

		if  > 0 {
			.Prefixes = make([]string, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .String()
			if  != nil {
				return fmt.Errorf("unable to decode help.countryCode#4203c5ef: field prefixes: %w", )
			}
			.Prefixes = append(.Prefixes, )
		}
	}
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode help.countryCode#4203c5ef: field patterns: %w", )
		}

		if  > 0 {
			.Patterns = make([]string, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .String()
			if  != nil {
				return fmt.Errorf("unable to decode help.countryCode#4203c5ef: field patterns: %w", )
			}
			.Patterns = append(.Patterns, )
		}
	}
	return nil
}

// GetCountryCode returns value of CountryCode field.
func ( *HelpCountryCode) () ( string) {
	if  == nil {
		return
	}
	return .CountryCode
}

// SetPrefixes sets value of Prefixes conditional field.
func ( *HelpCountryCode) ( []string) {
	.Flags.Set(0)
	.Prefixes = 
}

// GetPrefixes returns value of Prefixes conditional field and
// boolean which is true if field was set.
func ( *HelpCountryCode) () ( []string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Prefixes, true
}

// SetPatterns sets value of Patterns conditional field.
func ( *HelpCountryCode) ( []string) {
	.Flags.Set(1)
	.Patterns = 
}

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