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

// OnrampAvailability represents TL type `onrampAvailability#f9c84973`.
//
// See https://core.telegram.org/constructor/onrampAvailability for reference.
type OnrampAvailability struct {
	// Flags field of OnrampAvailability.
	Flags bin.Fields
	// Allowed field of OnrampAvailability.
	Allowed bool
	// BuyAllowed field of OnrampAvailability.
	BuyAllowed bool
	// CountryCode field of OnrampAvailability.
	CountryCode string
	// State field of OnrampAvailability.
	//
	// Use SetState and GetState helpers.
	State string
	// Methods field of OnrampAvailability.
	Methods []OnrampMethodAvailability
}

// OnrampAvailabilityTypeID is TL type id of OnrampAvailability.
const OnrampAvailabilityTypeID = 0xf9c84973

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

func ( *OnrampAvailability) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Allowed == false) {
		return false
	}
	if !(.BuyAllowed == false) {
		return false
	}
	if !(.CountryCode == "") {
		return false
	}
	if !(.State == "") {
		return false
	}
	if !(.Methods == nil) {
		return false
	}

	return true
}

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

// FillFrom fills OnrampAvailability from given interface.
func ( *OnrampAvailability) ( interface {
	() ( bool)
	() ( bool)
	() ( string)
	() ( string,  bool)
	() ( []OnrampMethodAvailability)
}) {
	.Allowed = .()
	.BuyAllowed = .()
	.CountryCode = .()
	if ,  := .();  {
		.State = 
	}

	.Methods = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *OnrampAvailability) () tdp.Type {
	 := tdp.Type{
		Name: "onrampAvailability",
		ID:   OnrampAvailabilityTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Allowed",
			SchemaName: "allowed",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "BuyAllowed",
			SchemaName: "buy_allowed",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "CountryCode",
			SchemaName: "country_code",
		},
		{
			Name:       "State",
			SchemaName: "state",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Methods",
			SchemaName: "methods",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *OnrampAvailability) () {
	if !(.Allowed == false) {
		.Flags.Set(0)
	}
	if !(.BuyAllowed == false) {
		.Flags.Set(1)
	}
	if !(.State == "") {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *OnrampAvailability) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode onrampAvailability#f9c84973 as nil")
	}
	.PutID(OnrampAvailabilityTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *OnrampAvailability) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode onrampAvailability#f9c84973 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode onrampAvailability#f9c84973: field flags: %w", )
	}
	.PutString(.CountryCode)
	if .Flags.Has(2) {
		.PutString(.State)
	}
	.PutVectorHeader(len(.Methods))
	for ,  := range .Methods {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode onrampAvailability#f9c84973: field methods element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *OnrampAvailability) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode onrampAvailability#f9c84973 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode onrampAvailability#f9c84973: field flags: %w", )
		}
	}
	.Allowed = .Flags.Has(0)
	.BuyAllowed = .Flags.Has(1)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode onrampAvailability#f9c84973: field country_code: %w", )
		}
		.CountryCode = 
	}
	if .Flags.Has(2) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode onrampAvailability#f9c84973: field state: %w", )
		}
		.State = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode onrampAvailability#f9c84973: field methods: %w", )
		}

		if  > 0 {
			.Methods = make([]OnrampMethodAvailability, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  OnrampMethodAvailability
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode onrampAvailability#f9c84973: field methods: %w", )
			}
			.Methods = append(.Methods, )
		}
	}
	return nil
}

// SetAllowed sets value of Allowed conditional field.
func ( *OnrampAvailability) ( bool) {
	if  {
		.Flags.Set(0)
		.Allowed = true
	} else {
		.Flags.Unset(0)
		.Allowed = false
	}
}

// GetAllowed returns value of Allowed conditional field.
func ( *OnrampAvailability) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetBuyAllowed sets value of BuyAllowed conditional field.
func ( *OnrampAvailability) ( bool) {
	if  {
		.Flags.Set(1)
		.BuyAllowed = true
	} else {
		.Flags.Unset(1)
		.BuyAllowed = false
	}
}

// GetBuyAllowed returns value of BuyAllowed conditional field.
func ( *OnrampAvailability) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

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

// SetState sets value of State conditional field.
func ( *OnrampAvailability) ( string) {
	.Flags.Set(2)
	.State = 
}

// GetState returns value of State conditional field and
// boolean which is true if field was set.
func ( *OnrampAvailability) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .State, true
}

// GetMethods returns value of Methods field.
func ( *OnrampAvailability) () ( []OnrampMethodAvailability) {
	if  == nil {
		return
	}
	return .Methods
}