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

// MessagesRequestSimpleWebViewRequest represents TL type `messages.requestSimpleWebView#1a46500a`.
// Open a bot mini app¹.
//
// Links:
//  1. https://core.telegram.org/api/bots/webapps
//
// See https://core.telegram.org/method/messages.requestSimpleWebView for reference.
type MessagesRequestSimpleWebViewRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the webapp was opened by clicking on the switch_webview button shown on top of
	// the inline results list returned by messages.getInlineBotResults¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/messages.getInlineBotResults
	FromSwitchWebview bool
	// Set this flag if opening the Mini App from the installed side menu entry »¹ or from
	// a Mini App link »².
	//
	// Links:
	//  1) https://core.telegram.org/api/bots/attach
	//  2) https://core.telegram.org/api/links#mini-app-links
	FromSideMenu bool
	// Bot that owns the mini app
	Bot InputUserClass
	// Web app URL, if opening from a keyboard button or inline result
	//
	// Use SetURL and GetURL helpers.
	URL string
	// Start parameter, if opening from a Mini App link »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/links#mini-app-links
	//
	// Use SetStartParam and GetStartParam helpers.
	StartParam string
	// Theme parameters »¹
	//
	// Links:
	//  1) https://core.telegram.org/api/bots/webapps#theme-parameters
	//
	// Use SetThemeParams and GetThemeParams helpers.
	ThemeParams DataJSON
	// Short name of the application; 0-64 English letters, digits, and underscores
	Platform string
}

// MessagesRequestSimpleWebViewRequestTypeID is TL type id of MessagesRequestSimpleWebViewRequest.
const MessagesRequestSimpleWebViewRequestTypeID = 0x1a46500a

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

func ( *MessagesRequestSimpleWebViewRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.FromSwitchWebview == false) {
		return false
	}
	if !(.FromSideMenu == false) {
		return false
	}
	if !(.Bot == nil) {
		return false
	}
	if !(.URL == "") {
		return false
	}
	if !(.StartParam == "") {
		return false
	}
	if !(.ThemeParams.Zero()) {
		return false
	}
	if !(.Platform == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesRequestSimpleWebViewRequest from given interface.
func ( *MessagesRequestSimpleWebViewRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( InputUserClass)
	() ( string,  bool)
	() ( string,  bool)
	() ( DataJSON,  bool)
	() ( string)
}) {
	.FromSwitchWebview = .()
	.FromSideMenu = .()
	.Bot = .()
	if ,  := .();  {
		.URL = 
	}

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

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

	.Platform = .()
}

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

// TypeName returns name of type in TL schema.
func (*MessagesRequestSimpleWebViewRequest) () string {
	return "messages.requestSimpleWebView"
}

// TypeInfo returns info about TL type.
func ( *MessagesRequestSimpleWebViewRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.requestSimpleWebView",
		ID:   MessagesRequestSimpleWebViewRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "FromSwitchWebview",
			SchemaName: "from_switch_webview",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "FromSideMenu",
			SchemaName: "from_side_menu",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Bot",
			SchemaName: "bot",
		},
		{
			Name:       "URL",
			SchemaName: "url",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "StartParam",
			SchemaName: "start_param",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "ThemeParams",
			SchemaName: "theme_params",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Platform",
			SchemaName: "platform",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesRequestSimpleWebViewRequest) () {
	if !(.FromSwitchWebview == false) {
		.Flags.Set(1)
	}
	if !(.FromSideMenu == false) {
		.Flags.Set(2)
	}
	if !(.URL == "") {
		.Flags.Set(3)
	}
	if !(.StartParam == "") {
		.Flags.Set(4)
	}
	if !(.ThemeParams.Zero()) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesRequestSimpleWebViewRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.requestSimpleWebView#1a46500a as nil")
	}
	.PutID(MessagesRequestSimpleWebViewRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesRequestSimpleWebViewRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.requestSimpleWebView#1a46500a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.requestSimpleWebView#1a46500a: field flags: %w", )
	}
	if .Bot == nil {
		return fmt.Errorf("unable to encode messages.requestSimpleWebView#1a46500a: field bot is nil")
	}
	if  := .Bot.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.requestSimpleWebView#1a46500a: field bot: %w", )
	}
	if .Flags.Has(3) {
		.PutString(.URL)
	}
	if .Flags.Has(4) {
		.PutString(.StartParam)
	}
	if .Flags.Has(0) {
		if  := .ThemeParams.Encode();  != nil {
			return fmt.Errorf("unable to encode messages.requestSimpleWebView#1a46500a: field theme_params: %w", )
		}
	}
	.PutString(.Platform)
	return nil
}

// Decode implements bin.Decoder.
func ( *MessagesRequestSimpleWebViewRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.requestSimpleWebView#1a46500a to nil")
	}
	if  := .ConsumeID(MessagesRequestSimpleWebViewRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode messages.requestSimpleWebView#1a46500a: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *MessagesRequestSimpleWebViewRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.requestSimpleWebView#1a46500a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.requestSimpleWebView#1a46500a: field flags: %w", )
		}
	}
	.FromSwitchWebview = .Flags.Has(1)
	.FromSideMenu = .Flags.Has(2)
	{
		,  := DecodeInputUser()
		if  != nil {
			return fmt.Errorf("unable to decode messages.requestSimpleWebView#1a46500a: field bot: %w", )
		}
		.Bot = 
	}
	if .Flags.Has(3) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.requestSimpleWebView#1a46500a: field url: %w", )
		}
		.URL = 
	}
	if .Flags.Has(4) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.requestSimpleWebView#1a46500a: field start_param: %w", )
		}
		.StartParam = 
	}
	if .Flags.Has(0) {
		if  := .ThemeParams.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.requestSimpleWebView#1a46500a: field theme_params: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.requestSimpleWebView#1a46500a: field platform: %w", )
		}
		.Platform = 
	}
	return nil
}

// SetFromSwitchWebview sets value of FromSwitchWebview conditional field.
func ( *MessagesRequestSimpleWebViewRequest) ( bool) {
	if  {
		.Flags.Set(1)
		.FromSwitchWebview = true
	} else {
		.Flags.Unset(1)
		.FromSwitchWebview = false
	}
}

// GetFromSwitchWebview returns value of FromSwitchWebview conditional field.
func ( *MessagesRequestSimpleWebViewRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetFromSideMenu sets value of FromSideMenu conditional field.
func ( *MessagesRequestSimpleWebViewRequest) ( bool) {
	if  {
		.Flags.Set(2)
		.FromSideMenu = true
	} else {
		.Flags.Unset(2)
		.FromSideMenu = false
	}
}

// GetFromSideMenu returns value of FromSideMenu conditional field.
func ( *MessagesRequestSimpleWebViewRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// GetBot returns value of Bot field.
func ( *MessagesRequestSimpleWebViewRequest) () ( InputUserClass) {
	if  == nil {
		return
	}
	return .Bot
}

// SetURL sets value of URL conditional field.
func ( *MessagesRequestSimpleWebViewRequest) ( string) {
	.Flags.Set(3)
	.URL = 
}

// GetURL returns value of URL conditional field and
// boolean which is true if field was set.
func ( *MessagesRequestSimpleWebViewRequest) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .URL, true
}

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

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

// SetThemeParams sets value of ThemeParams conditional field.
func ( *MessagesRequestSimpleWebViewRequest) ( DataJSON) {
	.Flags.Set(0)
	.ThemeParams = 
}

// GetThemeParams returns value of ThemeParams conditional field and
// boolean which is true if field was set.
func ( *MessagesRequestSimpleWebViewRequest) () ( DataJSON,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .ThemeParams, true
}

// GetPlatform returns value of Platform field.
func ( *MessagesRequestSimpleWebViewRequest) () ( string) {
	if  == nil {
		return
	}
	return .Platform
}

// MessagesRequestSimpleWebView invokes method messages.requestSimpleWebView#1a46500a returning error if any.
// Open a bot mini app¹.
//
// Links:
//  1. https://core.telegram.org/api/bots/webapps
//
// See https://core.telegram.org/method/messages.requestSimpleWebView for reference.
func ( *Client) ( context.Context,  *MessagesRequestSimpleWebViewRequest) (*SimpleWebViewResultURL, error) {
	var  SimpleWebViewResultURL

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return &, nil
}