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

// Page represents TL type `page#98657f0d`.
// Instant view¹ page
//
// Links:
//  1. https://instantview.telegram.org
//
// See https://core.telegram.org/constructor/page for reference.
type Page struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Indicates that not full page preview is available to the client and it will need to
	// fetch full Instant View from the server using messages.getWebPagePreview¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/messages.getWebPagePreview
	Part bool
	// Whether the page contains RTL text
	Rtl bool
	// Whether this is an IV v2¹ page
	//
	// Links:
	//  1) https://instantview.telegram.org/docs#what-39s-new-in-2-0
	V2 bool
	// Original page HTTP URL
	URL string
	// Page elements (like with HTML elements, only as TL constructors)
	Blocks []PageBlockClass
	// Photos in page
	Photos []PhotoClass
	// Media in page
	Documents []DocumentClass
	// View count
	//
	// Use SetViews and GetViews helpers.
	Views int
}

// PageTypeID is TL type id of Page.
const PageTypeID = 0x98657f0d

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

func ( *Page) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Part == false) {
		return false
	}
	if !(.Rtl == false) {
		return false
	}
	if !(.V2 == false) {
		return false
	}
	if !(.URL == "") {
		return false
	}
	if !(.Blocks == nil) {
		return false
	}
	if !(.Photos == nil) {
		return false
	}
	if !(.Documents == nil) {
		return false
	}
	if !(.Views == 0) {
		return false
	}

	return true
}

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

// FillFrom fills Page from given interface.
func ( *Page) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( string)
	() ( []PageBlockClass)
	() ( []PhotoClass)
	() ( []DocumentClass)
	() ( int,  bool)
}) {
	.Part = .()
	.Rtl = .()
	.V2 = .()
	.URL = .()
	.Blocks = .()
	.Photos = .()
	.Documents = .()
	if ,  := .();  {
		.Views = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *Page) () tdp.Type {
	 := tdp.Type{
		Name: "page",
		ID:   PageTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Part",
			SchemaName: "part",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Rtl",
			SchemaName: "rtl",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "V2",
			SchemaName: "v2",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "Blocks",
			SchemaName: "blocks",
		},
		{
			Name:       "Photos",
			SchemaName: "photos",
		},
		{
			Name:       "Documents",
			SchemaName: "documents",
		},
		{
			Name:       "Views",
			SchemaName: "views",
			Null:       !.Flags.Has(3),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *Page) () {
	if !(.Part == false) {
		.Flags.Set(0)
	}
	if !(.Rtl == false) {
		.Flags.Set(1)
	}
	if !(.V2 == false) {
		.Flags.Set(2)
	}
	if !(.Views == 0) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *Page) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode page#98657f0d as nil")
	}
	.PutID(PageTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *Page) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode page#98657f0d as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode page#98657f0d: field flags: %w", )
	}
	.PutString(.URL)
	.PutVectorHeader(len(.Blocks))
	for ,  := range .Blocks {
		if  == nil {
			return fmt.Errorf("unable to encode page#98657f0d: field blocks element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode page#98657f0d: field blocks element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Photos))
	for ,  := range .Photos {
		if  == nil {
			return fmt.Errorf("unable to encode page#98657f0d: field photos element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode page#98657f0d: field photos element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Documents))
	for ,  := range .Documents {
		if  == nil {
			return fmt.Errorf("unable to encode page#98657f0d: field documents element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode page#98657f0d: field documents element with index %d: %w", , )
		}
	}
	if .Flags.Has(3) {
		.PutInt(.Views)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *Page) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode page#98657f0d to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode page#98657f0d: field flags: %w", )
		}
	}
	.Part = .Flags.Has(0)
	.Rtl = .Flags.Has(1)
	.V2 = .Flags.Has(2)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode page#98657f0d: field url: %w", )
		}
		.URL = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode page#98657f0d: field blocks: %w", )
		}

		if  > 0 {
			.Blocks = make([]PageBlockClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePageBlock()
			if  != nil {
				return fmt.Errorf("unable to decode page#98657f0d: field blocks: %w", )
			}
			.Blocks = append(.Blocks, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode page#98657f0d: field photos: %w", )
		}

		if  > 0 {
			.Photos = make([]PhotoClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePhoto()
			if  != nil {
				return fmt.Errorf("unable to decode page#98657f0d: field photos: %w", )
			}
			.Photos = append(.Photos, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode page#98657f0d: field documents: %w", )
		}

		if  > 0 {
			.Documents = make([]DocumentClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeDocument()
			if  != nil {
				return fmt.Errorf("unable to decode page#98657f0d: field documents: %w", )
			}
			.Documents = append(.Documents, )
		}
	}
	if .Flags.Has(3) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode page#98657f0d: field views: %w", )
		}
		.Views = 
	}
	return nil
}

// SetPart sets value of Part conditional field.
func ( *Page) ( bool) {
	if  {
		.Flags.Set(0)
		.Part = true
	} else {
		.Flags.Unset(0)
		.Part = false
	}
}

// GetPart returns value of Part conditional field.
func ( *Page) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetRtl sets value of Rtl conditional field.
func ( *Page) ( bool) {
	if  {
		.Flags.Set(1)
		.Rtl = true
	} else {
		.Flags.Unset(1)
		.Rtl = false
	}
}

// GetRtl returns value of Rtl conditional field.
func ( *Page) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetV2 sets value of V2 conditional field.
func ( *Page) ( bool) {
	if  {
		.Flags.Set(2)
		.V2 = true
	} else {
		.Flags.Unset(2)
		.V2 = false
	}
}

// GetV2 returns value of V2 conditional field.
func ( *Page) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

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

// GetBlocks returns value of Blocks field.
func ( *Page) () ( []PageBlockClass) {
	if  == nil {
		return
	}
	return .Blocks
}

// GetPhotos returns value of Photos field.
func ( *Page) () ( []PhotoClass) {
	if  == nil {
		return
	}
	return .Photos
}

// GetDocuments returns value of Documents field.
func ( *Page) () ( []DocumentClass) {
	if  == nil {
		return
	}
	return .Documents
}

// SetViews sets value of Views conditional field.
func ( *Page) ( int) {
	.Flags.Set(3)
	.Views = 
}

// GetViews returns value of Views conditional field and
// boolean which is true if field was set.
func ( *Page) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Views, true
}

// MapBlocks returns field Blocks wrapped in PageBlockClassArray helper.
func ( *Page) () ( PageBlockClassArray) {
	return PageBlockClassArray(.Blocks)
}

// MapPhotos returns field Photos wrapped in PhotoClassArray helper.
func ( *Page) () ( PhotoClassArray) {
	return PhotoClassArray(.Photos)
}

// MapDocuments returns field Documents wrapped in DocumentClassArray helper.
func ( *Page) () ( DocumentClassArray) {
	return DocumentClassArray(.Documents)
}