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

// BusinessChatLink represents TL type `businessChatLink#b4ae666f`.
// Contains info about a business chat deep link »¹ created by the current account.
//
// Links:
//  1. https://core.telegram.org/api/business#business-chat-links
//
// See https://core.telegram.org/constructor/businessChatLink for reference.
type BusinessChatLink struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Business chat deep link¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/links#business-chat-links
	Link string
	// Message to pre-fill in the message input field.
	Message string
	// Message entities for styled text¹
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	//
	// Use SetEntities and GetEntities helpers.
	Entities []MessageEntityClass
	// Human-readable name of the link, to simplify management in the UI (only visible to the
	// creator of the link).
	//
	// Use SetTitle and GetTitle helpers.
	Title string
	// Number of times the link was resolved (clicked/scanned/etc...).
	Views int
}

// BusinessChatLinkTypeID is TL type id of BusinessChatLink.
const BusinessChatLinkTypeID = 0xb4ae666f

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

func ( *BusinessChatLink) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Link == "") {
		return false
	}
	if !(.Message == "") {
		return false
	}
	if !(.Entities == nil) {
		return false
	}
	if !(.Title == "") {
		return false
	}
	if !(.Views == 0) {
		return false
	}

	return true
}

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

// FillFrom fills BusinessChatLink from given interface.
func ( *BusinessChatLink) ( interface {
	() ( string)
	() ( string)
	() ( []MessageEntityClass,  bool)
	() ( string,  bool)
	() ( int)
}) {
	.Link = .()
	.Message = .()
	if ,  := .();  {
		.Entities = 
	}

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

	.Views = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *BusinessChatLink) () tdp.Type {
	 := tdp.Type{
		Name: "businessChatLink",
		ID:   BusinessChatLinkTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Link",
			SchemaName: "link",
		},
		{
			Name:       "Message",
			SchemaName: "message",
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Title",
			SchemaName: "title",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Views",
			SchemaName: "views",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *BusinessChatLink) () {
	if !(.Entities == nil) {
		.Flags.Set(0)
	}
	if !(.Title == "") {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *BusinessChatLink) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode businessChatLink#b4ae666f as nil")
	}
	.PutID(BusinessChatLinkTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *BusinessChatLink) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode businessChatLink#b4ae666f as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode businessChatLink#b4ae666f: field flags: %w", )
	}
	.PutString(.Link)
	.PutString(.Message)
	if .Flags.Has(0) {
		.PutVectorHeader(len(.Entities))
		for ,  := range .Entities {
			if  == nil {
				return fmt.Errorf("unable to encode businessChatLink#b4ae666f: field entities element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode businessChatLink#b4ae666f: field entities element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(1) {
		.PutString(.Title)
	}
	.PutInt(.Views)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *BusinessChatLink) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode businessChatLink#b4ae666f to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode businessChatLink#b4ae666f: field flags: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode businessChatLink#b4ae666f: field link: %w", )
		}
		.Link = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode businessChatLink#b4ae666f: field message: %w", )
		}
		.Message = 
	}
	if .Flags.Has(0) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode businessChatLink#b4ae666f: field entities: %w", )
		}

		if  > 0 {
			.Entities = make([]MessageEntityClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessageEntity()
			if  != nil {
				return fmt.Errorf("unable to decode businessChatLink#b4ae666f: field entities: %w", )
			}
			.Entities = append(.Entities, )
		}
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode businessChatLink#b4ae666f: field title: %w", )
		}
		.Title = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode businessChatLink#b4ae666f: field views: %w", )
		}
		.Views = 
	}
	return nil
}

// GetLink returns value of Link field.
func ( *BusinessChatLink) () ( string) {
	if  == nil {
		return
	}
	return .Link
}

// GetMessage returns value of Message field.
func ( *BusinessChatLink) () ( string) {
	if  == nil {
		return
	}
	return .Message
}

// SetEntities sets value of Entities conditional field.
func ( *BusinessChatLink) ( []MessageEntityClass) {
	.Flags.Set(0)
	.Entities = 
}

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

// SetTitle sets value of Title conditional field.
func ( *BusinessChatLink) ( string) {
	.Flags.Set(1)
	.Title = 
}

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

// GetViews returns value of Views field.
func ( *BusinessChatLink) () ( int) {
	if  == nil {
		return
	}
	return .Views
}

// MapEntities returns field Entities wrapped in MessageEntityClassArray helper.
func ( *BusinessChatLink) () ( MessageEntityClassArray,  bool) {
	if !.Flags.Has(0) {
		return , false
	}
	return MessageEntityClassArray(.Entities), true
}