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

// SponsoredMessage represents TL type `sponsoredMessage#ed5383f7`.
// A sponsored message¹.
//
// Links:
//  1. https://core.telegram.org/api/sponsored-messages
//
// See https://core.telegram.org/constructor/sponsoredMessage for reference.
type SponsoredMessage struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the message needs to be labeled as "recommended" instead of "sponsored"
	Recommended bool
	// Whether a profile photo bubble should be displayed for this message, like for messages
	// sent in groups. The photo shown in the bubble is obtained either from the peer
	// contained in from_id, or from chat_invite.
	ShowPeerPhoto bool
	// Message ID
	RandomID []byte
	// ID of the sender of the message
	//
	// Use SetFromID and GetFromID helpers.
	FromID PeerClass
	// Information about the chat invite hash specified in chat_invite_hash
	//
	// Use SetChatInvite and GetChatInvite helpers.
	ChatInvite ChatInviteClass
	// Chat invite
	//
	// Use SetChatInviteHash and GetChatInviteHash helpers.
	ChatInviteHash string
	// Optional link to a channel post if from_id points to a channel
	//
	// Use SetChannelPost and GetChannelPost helpers.
	ChannelPost int
	// Parameter for the bot start message if the sponsored chat is a chat with a bot.
	//
	// Use SetStartParam and GetStartParam helpers.
	StartParam string
	// Sponsored website
	//
	// Use SetWebpage and GetWebpage helpers.
	Webpage SponsoredWebPage
	// Mini App »¹ to open when the sponsored message is clicked.
	//
	// Links:
	//  1) https://core.telegram.org/api/bots/webapps
	//
	// Use SetApp and GetApp helpers.
	App BotAppClass
	// Sponsored message
	Message string
	// Message entities for styled text¹
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	//
	// Use SetEntities and GetEntities helpers.
	Entities []MessageEntityClass
	// Text of the sponsored message button.
	//
	// Use SetButtonText and GetButtonText helpers.
	ButtonText string
	// If set, contains additional information about the sponsor to be shown along with the
	// message.
	//
	// Use SetSponsorInfo and GetSponsorInfo helpers.
	SponsorInfo string
	// If set, contains additional information about the sponsored message to be shown along
	// with the message.
	//
	// Use SetAdditionalInfo and GetAdditionalInfo helpers.
	AdditionalInfo string
}

// SponsoredMessageTypeID is TL type id of SponsoredMessage.
const SponsoredMessageTypeID = 0xed5383f7

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

func ( *SponsoredMessage) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Recommended == false) {
		return false
	}
	if !(.ShowPeerPhoto == false) {
		return false
	}
	if !(.RandomID == nil) {
		return false
	}
	if !(.FromID == nil) {
		return false
	}
	if !(.ChatInvite == nil) {
		return false
	}
	if !(.ChatInviteHash == "") {
		return false
	}
	if !(.ChannelPost == 0) {
		return false
	}
	if !(.StartParam == "") {
		return false
	}
	if !(.Webpage.Zero()) {
		return false
	}
	if !(.App == nil) {
		return false
	}
	if !(.Message == "") {
		return false
	}
	if !(.Entities == nil) {
		return false
	}
	if !(.ButtonText == "") {
		return false
	}
	if !(.SponsorInfo == "") {
		return false
	}
	if !(.AdditionalInfo == "") {
		return false
	}

	return true
}

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

// FillFrom fills SponsoredMessage from given interface.
func ( *SponsoredMessage) ( interface {
	() ( bool)
	() ( bool)
	() ( []byte)
	() ( PeerClass,  bool)
	() ( ChatInviteClass,  bool)
	() ( string,  bool)
	() ( int,  bool)
	() ( string,  bool)
	() ( SponsoredWebPage,  bool)
	() ( BotAppClass,  bool)
	() ( string)
	() ( []MessageEntityClass,  bool)
	() ( string,  bool)
	() ( string,  bool)
	() ( string,  bool)
}) {
	.Recommended = .()
	.ShowPeerPhoto = .()
	.RandomID = .()
	if ,  := .();  {
		.FromID = 
	}

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

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

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

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

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

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

	.Message = .()
	if ,  := .();  {
		.Entities = 
	}

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *SponsoredMessage) () tdp.Type {
	 := tdp.Type{
		Name: "sponsoredMessage",
		ID:   SponsoredMessageTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Recommended",
			SchemaName: "recommended",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "ShowPeerPhoto",
			SchemaName: "show_peer_photo",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "RandomID",
			SchemaName: "random_id",
		},
		{
			Name:       "FromID",
			SchemaName: "from_id",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "ChatInvite",
			SchemaName: "chat_invite",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "ChatInviteHash",
			SchemaName: "chat_invite_hash",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "ChannelPost",
			SchemaName: "channel_post",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "StartParam",
			SchemaName: "start_param",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Webpage",
			SchemaName: "webpage",
			Null:       !.Flags.Has(9),
		},
		{
			Name:       "App",
			SchemaName: "app",
			Null:       !.Flags.Has(10),
		},
		{
			Name:       "Message",
			SchemaName: "message",
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "ButtonText",
			SchemaName: "button_text",
			Null:       !.Flags.Has(11),
		},
		{
			Name:       "SponsorInfo",
			SchemaName: "sponsor_info",
			Null:       !.Flags.Has(7),
		},
		{
			Name:       "AdditionalInfo",
			SchemaName: "additional_info",
			Null:       !.Flags.Has(8),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *SponsoredMessage) () {
	if !(.Recommended == false) {
		.Flags.Set(5)
	}
	if !(.ShowPeerPhoto == false) {
		.Flags.Set(6)
	}
	if !(.FromID == nil) {
		.Flags.Set(3)
	}
	if !(.ChatInvite == nil) {
		.Flags.Set(4)
	}
	if !(.ChatInviteHash == "") {
		.Flags.Set(4)
	}
	if !(.ChannelPost == 0) {
		.Flags.Set(2)
	}
	if !(.StartParam == "") {
		.Flags.Set(0)
	}
	if !(.Webpage.Zero()) {
		.Flags.Set(9)
	}
	if !(.App == nil) {
		.Flags.Set(10)
	}
	if !(.Entities == nil) {
		.Flags.Set(1)
	}
	if !(.ButtonText == "") {
		.Flags.Set(11)
	}
	if !(.SponsorInfo == "") {
		.Flags.Set(7)
	}
	if !(.AdditionalInfo == "") {
		.Flags.Set(8)
	}
}

// Encode implements bin.Encoder.
func ( *SponsoredMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode sponsoredMessage#ed5383f7 as nil")
	}
	.PutID(SponsoredMessageTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *SponsoredMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode sponsoredMessage#ed5383f7 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode sponsoredMessage#ed5383f7: field flags: %w", )
	}
	.PutBytes(.RandomID)
	if .Flags.Has(3) {
		if .FromID == nil {
			return fmt.Errorf("unable to encode sponsoredMessage#ed5383f7: field from_id is nil")
		}
		if  := .FromID.Encode();  != nil {
			return fmt.Errorf("unable to encode sponsoredMessage#ed5383f7: field from_id: %w", )
		}
	}
	if .Flags.Has(4) {
		if .ChatInvite == nil {
			return fmt.Errorf("unable to encode sponsoredMessage#ed5383f7: field chat_invite is nil")
		}
		if  := .ChatInvite.Encode();  != nil {
			return fmt.Errorf("unable to encode sponsoredMessage#ed5383f7: field chat_invite: %w", )
		}
	}
	if .Flags.Has(4) {
		.PutString(.ChatInviteHash)
	}
	if .Flags.Has(2) {
		.PutInt(.ChannelPost)
	}
	if .Flags.Has(0) {
		.PutString(.StartParam)
	}
	if .Flags.Has(9) {
		if  := .Webpage.Encode();  != nil {
			return fmt.Errorf("unable to encode sponsoredMessage#ed5383f7: field webpage: %w", )
		}
	}
	if .Flags.Has(10) {
		if .App == nil {
			return fmt.Errorf("unable to encode sponsoredMessage#ed5383f7: field app is nil")
		}
		if  := .App.Encode();  != nil {
			return fmt.Errorf("unable to encode sponsoredMessage#ed5383f7: field app: %w", )
		}
	}
	.PutString(.Message)
	if .Flags.Has(1) {
		.PutVectorHeader(len(.Entities))
		for ,  := range .Entities {
			if  == nil {
				return fmt.Errorf("unable to encode sponsoredMessage#ed5383f7: field entities element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode sponsoredMessage#ed5383f7: field entities element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(11) {
		.PutString(.ButtonText)
	}
	if .Flags.Has(7) {
		.PutString(.SponsorInfo)
	}
	if .Flags.Has(8) {
		.PutString(.AdditionalInfo)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *SponsoredMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode sponsoredMessage#ed5383f7 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field flags: %w", )
		}
	}
	.Recommended = .Flags.Has(5)
	.ShowPeerPhoto = .Flags.Has(6)
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field random_id: %w", )
		}
		.RandomID = 
	}
	if .Flags.Has(3) {
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field from_id: %w", )
		}
		.FromID = 
	}
	if .Flags.Has(4) {
		,  := DecodeChatInvite()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field chat_invite: %w", )
		}
		.ChatInvite = 
	}
	if .Flags.Has(4) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field chat_invite_hash: %w", )
		}
		.ChatInviteHash = 
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field channel_post: %w", )
		}
		.ChannelPost = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field start_param: %w", )
		}
		.StartParam = 
	}
	if .Flags.Has(9) {
		if  := .Webpage.Decode();  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field webpage: %w", )
		}
	}
	if .Flags.Has(10) {
		,  := DecodeBotApp()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field app: %w", )
		}
		.App = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field message: %w", )
		}
		.Message = 
	}
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field entities: %w", )
		}

		if  > 0 {
			.Entities = make([]MessageEntityClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessageEntity()
			if  != nil {
				return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field entities: %w", )
			}
			.Entities = append(.Entities, )
		}
	}
	if .Flags.Has(11) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field button_text: %w", )
		}
		.ButtonText = 
	}
	if .Flags.Has(7) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field sponsor_info: %w", )
		}
		.SponsorInfo = 
	}
	if .Flags.Has(8) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredMessage#ed5383f7: field additional_info: %w", )
		}
		.AdditionalInfo = 
	}
	return nil
}

// SetRecommended sets value of Recommended conditional field.
func ( *SponsoredMessage) ( bool) {
	if  {
		.Flags.Set(5)
		.Recommended = true
	} else {
		.Flags.Unset(5)
		.Recommended = false
	}
}

// GetRecommended returns value of Recommended conditional field.
func ( *SponsoredMessage) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

// SetShowPeerPhoto sets value of ShowPeerPhoto conditional field.
func ( *SponsoredMessage) ( bool) {
	if  {
		.Flags.Set(6)
		.ShowPeerPhoto = true
	} else {
		.Flags.Unset(6)
		.ShowPeerPhoto = false
	}
}

// GetShowPeerPhoto returns value of ShowPeerPhoto conditional field.
func ( *SponsoredMessage) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(6)
}

// GetRandomID returns value of RandomID field.
func ( *SponsoredMessage) () ( []byte) {
	if  == nil {
		return
	}
	return .RandomID
}

// SetFromID sets value of FromID conditional field.
func ( *SponsoredMessage) ( PeerClass) {
	.Flags.Set(3)
	.FromID = 
}

// GetFromID returns value of FromID conditional field and
// boolean which is true if field was set.
func ( *SponsoredMessage) () ( PeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .FromID, true
}

// SetChatInvite sets value of ChatInvite conditional field.
func ( *SponsoredMessage) ( ChatInviteClass) {
	.Flags.Set(4)
	.ChatInvite = 
}

// GetChatInvite returns value of ChatInvite conditional field and
// boolean which is true if field was set.
func ( *SponsoredMessage) () ( ChatInviteClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .ChatInvite, true
}

// SetChatInviteHash sets value of ChatInviteHash conditional field.
func ( *SponsoredMessage) ( string) {
	.Flags.Set(4)
	.ChatInviteHash = 
}

// GetChatInviteHash returns value of ChatInviteHash conditional field and
// boolean which is true if field was set.
func ( *SponsoredMessage) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .ChatInviteHash, true
}

// SetChannelPost sets value of ChannelPost conditional field.
func ( *SponsoredMessage) ( int) {
	.Flags.Set(2)
	.ChannelPost = 
}

// GetChannelPost returns value of ChannelPost conditional field and
// boolean which is true if field was set.
func ( *SponsoredMessage) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .ChannelPost, true
}

// SetStartParam sets value of StartParam conditional field.
func ( *SponsoredMessage) ( string) {
	.Flags.Set(0)
	.StartParam = 
}

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

// SetWebpage sets value of Webpage conditional field.
func ( *SponsoredMessage) ( SponsoredWebPage) {
	.Flags.Set(9)
	.Webpage = 
}

// GetWebpage returns value of Webpage conditional field and
// boolean which is true if field was set.
func ( *SponsoredMessage) () ( SponsoredWebPage,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(9) {
		return , false
	}
	return .Webpage, true
}

// SetApp sets value of App conditional field.
func ( *SponsoredMessage) ( BotAppClass) {
	.Flags.Set(10)
	.App = 
}

// GetApp returns value of App conditional field and
// boolean which is true if field was set.
func ( *SponsoredMessage) () ( BotAppClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(10) {
		return , false
	}
	return .App, true
}

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

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

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

// SetButtonText sets value of ButtonText conditional field.
func ( *SponsoredMessage) ( string) {
	.Flags.Set(11)
	.ButtonText = 
}

// GetButtonText returns value of ButtonText conditional field and
// boolean which is true if field was set.
func ( *SponsoredMessage) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(11) {
		return , false
	}
	return .ButtonText, true
}

// SetSponsorInfo sets value of SponsorInfo conditional field.
func ( *SponsoredMessage) ( string) {
	.Flags.Set(7)
	.SponsorInfo = 
}

// GetSponsorInfo returns value of SponsorInfo conditional field and
// boolean which is true if field was set.
func ( *SponsoredMessage) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(7) {
		return , false
	}
	return .SponsorInfo, true
}

// SetAdditionalInfo sets value of AdditionalInfo conditional field.
func ( *SponsoredMessage) ( string) {
	.Flags.Set(8)
	.AdditionalInfo = 
}

// GetAdditionalInfo returns value of AdditionalInfo conditional field and
// boolean which is true if field was set.
func ( *SponsoredMessage) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(8) {
		return , false
	}
	return .AdditionalInfo, true
}

// GetAppAsModified returns mapped value of App conditional field and
// boolean which is true if field was set.
func ( *SponsoredMessage) () (*BotApp, bool) {
	if ,  := .GetApp();  {
		return .AsModified()
	}
	return nil, false
}

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