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

// AccessPointRule represents TL type `accessPointRule#4679b65f`.
//
// See https://core.telegram.org/constructor/accessPointRule for reference.
type AccessPointRule struct {
	// PhonePrefixRules field of AccessPointRule.
	PhonePrefixRules string
	// DCID field of AccessPointRule.
	DCID int
	// IPs field of AccessPointRule.
	IPs []IPPortClass
}

// AccessPointRuleTypeID is TL type id of AccessPointRule.
const AccessPointRuleTypeID = 0x4679b65f

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

func ( *AccessPointRule) () bool {
	if  == nil {
		return true
	}
	if !(.PhonePrefixRules == "") {
		return false
	}
	if !(.DCID == 0) {
		return false
	}
	if !(.IPs == nil) {
		return false
	}

	return true
}

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

// FillFrom fills AccessPointRule from given interface.
func ( *AccessPointRule) ( interface {
	() ( string)
	() ( int)
	() ( []IPPortClass)
}) {
	.PhonePrefixRules = .()
	.DCID = .()
	.IPs = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *AccessPointRule) () tdp.Type {
	 := tdp.Type{
		Name: "accessPointRule",
		ID:   AccessPointRuleTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "PhonePrefixRules",
			SchemaName: "phone_prefix_rules",
		},
		{
			Name:       "DCID",
			SchemaName: "dc_id",
		},
		{
			Name:       "IPs",
			SchemaName: "ips",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *AccessPointRule) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode accessPointRule#4679b65f as nil")
	}
	.PutID(AccessPointRuleTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *AccessPointRule) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode accessPointRule#4679b65f as nil")
	}
	.PutString(.PhonePrefixRules)
	.PutInt(.DCID)
	.PutInt(len(.IPs))
	for ,  := range .IPs {
		if  == nil {
			return fmt.Errorf("unable to encode accessPointRule#4679b65f: field ips element with index %d is nil", )
		}
		if  := .EncodeBare();  != nil {
			return fmt.Errorf("unable to encode bare accessPointRule#4679b65f: field ips element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *AccessPointRule) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode accessPointRule#4679b65f to nil")
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode accessPointRule#4679b65f: field phone_prefix_rules: %w", )
		}
		.PhonePrefixRules = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode accessPointRule#4679b65f: field dc_id: %w", )
		}
		.DCID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode accessPointRule#4679b65f: field ips: %w", )
		}

		if  > 0 {
			.IPs = make([]IPPortClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeIPPort()
			if  != nil {
				return fmt.Errorf("unable to decode accessPointRule#4679b65f: field ips: %w", )
			}
			.IPs = append(.IPs, )
		}
	}
	return nil
}

// GetPhonePrefixRules returns value of PhonePrefixRules field.
func ( *AccessPointRule) () ( string) {
	if  == nil {
		return
	}
	return .PhonePrefixRules
}

// GetDCID returns value of DCID field.
func ( *AccessPointRule) () ( int) {
	if  == nil {
		return
	}
	return .DCID
}

// GetIPs returns value of IPs field.
func ( *AccessPointRule) () ( []IPPortClass) {
	if  == nil {
		return
	}
	return .IPs
}

// MapIPs returns field IPs wrapped in IPPortClassArray helper.
func ( *AccessPointRule) () ( IPPortClassArray) {
	return IPPortClassArray(.IPs)
}