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

// PageRelatedArticle represents TL type `pageRelatedArticle#b390dc08`.
// Related article
//
// See https://core.telegram.org/constructor/pageRelatedArticle for reference.
type PageRelatedArticle struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// URL of article
	URL string
	// Webpage ID of generated IV preview
	WebpageID int64
	// Title
	//
	// Use SetTitle and GetTitle helpers.
	Title string
	// Description
	//
	// Use SetDescription and GetDescription helpers.
	Description string
	// ID of preview photo
	//
	// Use SetPhotoID and GetPhotoID helpers.
	PhotoID int64
	// Author name
	//
	// Use SetAuthor and GetAuthor helpers.
	Author string
	// Date of publication
	//
	// Use SetPublishedDate and GetPublishedDate helpers.
	PublishedDate int
}

// PageRelatedArticleTypeID is TL type id of PageRelatedArticle.
const PageRelatedArticleTypeID = 0xb390dc08

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

func ( *PageRelatedArticle) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.URL == "") {
		return false
	}
	if !(.WebpageID == 0) {
		return false
	}
	if !(.Title == "") {
		return false
	}
	if !(.Description == "") {
		return false
	}
	if !(.PhotoID == 0) {
		return false
	}
	if !(.Author == "") {
		return false
	}
	if !(.PublishedDate == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PageRelatedArticle from given interface.
func ( *PageRelatedArticle) ( interface {
	() ( string)
	() ( int64)
	() ( string,  bool)
	() ( string,  bool)
	() ( int64,  bool)
	() ( string,  bool)
	() ( int,  bool)
}) {
	.URL = .()
	.WebpageID = .()
	if ,  := .();  {
		.Title = 
	}

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

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *PageRelatedArticle) () tdp.Type {
	 := tdp.Type{
		Name: "pageRelatedArticle",
		ID:   PageRelatedArticleTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "WebpageID",
			SchemaName: "webpage_id",
		},
		{
			Name:       "Title",
			SchemaName: "title",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Description",
			SchemaName: "description",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "PhotoID",
			SchemaName: "photo_id",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Author",
			SchemaName: "author",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "PublishedDate",
			SchemaName: "published_date",
			Null:       !.Flags.Has(4),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *PageRelatedArticle) () {
	if !(.Title == "") {
		.Flags.Set(0)
	}
	if !(.Description == "") {
		.Flags.Set(1)
	}
	if !(.PhotoID == 0) {
		.Flags.Set(2)
	}
	if !(.Author == "") {
		.Flags.Set(3)
	}
	if !(.PublishedDate == 0) {
		.Flags.Set(4)
	}
}

// Encode implements bin.Encoder.
func ( *PageRelatedArticle) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pageRelatedArticle#b390dc08 as nil")
	}
	.PutID(PageRelatedArticleTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PageRelatedArticle) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode pageRelatedArticle#b390dc08 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode pageRelatedArticle#b390dc08: field flags: %w", )
	}
	.PutString(.URL)
	.PutLong(.WebpageID)
	if .Flags.Has(0) {
		.PutString(.Title)
	}
	if .Flags.Has(1) {
		.PutString(.Description)
	}
	if .Flags.Has(2) {
		.PutLong(.PhotoID)
	}
	if .Flags.Has(3) {
		.PutString(.Author)
	}
	if .Flags.Has(4) {
		.PutInt(.PublishedDate)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PageRelatedArticle) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode pageRelatedArticle#b390dc08 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode pageRelatedArticle#b390dc08: field flags: %w", )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode pageRelatedArticle#b390dc08: field url: %w", )
		}
		.URL = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode pageRelatedArticle#b390dc08: field webpage_id: %w", )
		}
		.WebpageID = 
	}
	if .Flags.Has(0) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode pageRelatedArticle#b390dc08: field title: %w", )
		}
		.Title = 
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode pageRelatedArticle#b390dc08: field description: %w", )
		}
		.Description = 
	}
	if .Flags.Has(2) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode pageRelatedArticle#b390dc08: field photo_id: %w", )
		}
		.PhotoID = 
	}
	if .Flags.Has(3) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode pageRelatedArticle#b390dc08: field author: %w", )
		}
		.Author = 
	}
	if .Flags.Has(4) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode pageRelatedArticle#b390dc08: field published_date: %w", )
		}
		.PublishedDate = 
	}
	return nil
}

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

// GetWebpageID returns value of WebpageID field.
func ( *PageRelatedArticle) () ( int64) {
	if  == nil {
		return
	}
	return .WebpageID
}

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

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

// SetDescription sets value of Description conditional field.
func ( *PageRelatedArticle) ( string) {
	.Flags.Set(1)
	.Description = 
}

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

// SetPhotoID sets value of PhotoID conditional field.
func ( *PageRelatedArticle) ( int64) {
	.Flags.Set(2)
	.PhotoID = 
}

// GetPhotoID returns value of PhotoID conditional field and
// boolean which is true if field was set.
func ( *PageRelatedArticle) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .PhotoID, true
}

// SetAuthor sets value of Author conditional field.
func ( *PageRelatedArticle) ( string) {
	.Flags.Set(3)
	.Author = 
}

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

// SetPublishedDate sets value of PublishedDate conditional field.
func ( *PageRelatedArticle) ( int) {
	.Flags.Set(4)
	.PublishedDate = 
}

// GetPublishedDate returns value of PublishedDate conditional field and
// boolean which is true if field was set.
func ( *PageRelatedArticle) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .PublishedDate, true
}