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

// SponsoredWebPage represents TL type `sponsoredWebPage#3db8ec63`.
// Represents a sponsored website.
//
// See https://core.telegram.org/constructor/sponsoredWebPage for reference.
type SponsoredWebPage struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Web page URL.
	URL string
	// Website name.
	SiteName string
	// Optional image preview.
	//
	// Use SetPhoto and GetPhoto helpers.
	Photo PhotoClass
}

// SponsoredWebPageTypeID is TL type id of SponsoredWebPage.
const SponsoredWebPageTypeID = 0x3db8ec63

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

func ( *SponsoredWebPage) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.URL == "") {
		return false
	}
	if !(.SiteName == "") {
		return false
	}
	if !(.Photo == nil) {
		return false
	}

	return true
}

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

// FillFrom fills SponsoredWebPage from given interface.
func ( *SponsoredWebPage) ( interface {
	() ( string)
	() ( string)
	() ( PhotoClass,  bool)
}) {
	.URL = .()
	.SiteName = .()
	if ,  := .();  {
		.Photo = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *SponsoredWebPage) () tdp.Type {
	 := tdp.Type{
		Name: "sponsoredWebPage",
		ID:   SponsoredWebPageTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "SiteName",
			SchemaName: "site_name",
		},
		{
			Name:       "Photo",
			SchemaName: "photo",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *SponsoredWebPage) () {
	if !(.Photo == nil) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *SponsoredWebPage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode sponsoredWebPage#3db8ec63 as nil")
	}
	.PutID(SponsoredWebPageTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *SponsoredWebPage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode sponsoredWebPage#3db8ec63 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode sponsoredWebPage#3db8ec63: field flags: %w", )
	}
	.PutString(.URL)
	.PutString(.SiteName)
	if .Flags.Has(0) {
		if .Photo == nil {
			return fmt.Errorf("unable to encode sponsoredWebPage#3db8ec63: field photo is nil")
		}
		if  := .Photo.Encode();  != nil {
			return fmt.Errorf("unable to encode sponsoredWebPage#3db8ec63: field photo: %w", )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *SponsoredWebPage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode sponsoredWebPage#3db8ec63 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode sponsoredWebPage#3db8ec63: field flags: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredWebPage#3db8ec63: field url: %w", )
		}
		.URL = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredWebPage#3db8ec63: field site_name: %w", )
		}
		.SiteName = 
	}
	if .Flags.Has(0) {
		,  := DecodePhoto()
		if  != nil {
			return fmt.Errorf("unable to decode sponsoredWebPage#3db8ec63: field photo: %w", )
		}
		.Photo = 
	}
	return nil
}

// GetURL returns value of URL field.
func ( *SponsoredWebPage) () ( string) {
	if  == nil {
		return
	}
	return .URL
}

// GetSiteName returns value of SiteName field.
func ( *SponsoredWebPage) () ( string) {
	if  == nil {
		return
	}
	return .SiteName
}

// SetPhoto sets value of Photo conditional field.
func ( *SponsoredWebPage) ( PhotoClass) {
	.Flags.Set(0)
	.Photo = 
}

// GetPhoto returns value of Photo conditional field and
// boolean which is true if field was set.
func ( *SponsoredWebPage) () ( PhotoClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Photo, true
}

// GetPhotoAsNotEmpty returns mapped value of Photo conditional field and
// boolean which is true if field was set.
func ( *SponsoredWebPage) () (*Photo, bool) {
	if ,  := .GetPhoto();  {
		return .AsNotEmpty()
	}
	return nil, false
}