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

// WebDocument represents TL type `webDocument#1c570ed1`.
// Remote document
//
// See https://core.telegram.org/constructor/webDocument for reference.
type WebDocument struct {
	// Document URL
	URL string
	// Access hash
	AccessHash int64
	// File size
	Size int
	// MIME type
	MimeType string
	// Attributes for media types
	Attributes []DocumentAttributeClass
}

// WebDocumentTypeID is TL type id of WebDocument.
const WebDocumentTypeID = 0x1c570ed1

// construct implements constructor of WebDocumentClass.
func ( WebDocument) () WebDocumentClass { return & }

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

	_ WebDocumentClass = &WebDocument{}
)

func ( *WebDocument) () bool {
	if  == nil {
		return true
	}
	if !(.URL == "") {
		return false
	}
	if !(.AccessHash == 0) {
		return false
	}
	if !(.Size == 0) {
		return false
	}
	if !(.MimeType == "") {
		return false
	}
	if !(.Attributes == nil) {
		return false
	}

	return true
}

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

// FillFrom fills WebDocument from given interface.
func ( *WebDocument) ( interface {
	() ( string)
	() ( int64)
	() ( int)
	() ( string)
	() ( []DocumentAttributeClass)
}) {
	.URL = .()
	.AccessHash = .()
	.Size = .()
	.MimeType = .()
	.Attributes = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *WebDocument) () tdp.Type {
	 := tdp.Type{
		Name: "webDocument",
		ID:   WebDocumentTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "AccessHash",
			SchemaName: "access_hash",
		},
		{
			Name:       "Size",
			SchemaName: "size",
		},
		{
			Name:       "MimeType",
			SchemaName: "mime_type",
		},
		{
			Name:       "Attributes",
			SchemaName: "attributes",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *WebDocument) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode webDocument#1c570ed1 as nil")
	}
	.PutID(WebDocumentTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *WebDocument) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode webDocument#1c570ed1 as nil")
	}
	.PutString(.URL)
	.PutLong(.AccessHash)
	.PutInt(.Size)
	.PutString(.MimeType)
	.PutVectorHeader(len(.Attributes))
	for ,  := range .Attributes {
		if  == nil {
			return fmt.Errorf("unable to encode webDocument#1c570ed1: field attributes element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode webDocument#1c570ed1: field attributes element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *WebDocument) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode webDocument#1c570ed1 to nil")
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode webDocument#1c570ed1: field url: %w", )
		}
		.URL = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode webDocument#1c570ed1: field access_hash: %w", )
		}
		.AccessHash = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode webDocument#1c570ed1: field size: %w", )
		}
		.Size = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode webDocument#1c570ed1: field mime_type: %w", )
		}
		.MimeType = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode webDocument#1c570ed1: field attributes: %w", )
		}

		if  > 0 {
			.Attributes = make([]DocumentAttributeClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeDocumentAttribute()
			if  != nil {
				return fmt.Errorf("unable to decode webDocument#1c570ed1: field attributes: %w", )
			}
			.Attributes = append(.Attributes, )
		}
	}
	return nil
}

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

// GetAccessHash returns value of AccessHash field.
func ( *WebDocument) () ( int64) {
	if  == nil {
		return
	}
	return .AccessHash
}

// GetSize returns value of Size field.
func ( *WebDocument) () ( int) {
	if  == nil {
		return
	}
	return .Size
}

// GetMimeType returns value of MimeType field.
func ( *WebDocument) () ( string) {
	if  == nil {
		return
	}
	return .MimeType
}

// GetAttributes returns value of Attributes field.
func ( *WebDocument) () ( []DocumentAttributeClass) {
	if  == nil {
		return
	}
	return .Attributes
}

// MapAttributes returns field Attributes wrapped in DocumentAttributeClassArray helper.
func ( *WebDocument) () ( DocumentAttributeClassArray) {
	return DocumentAttributeClassArray(.Attributes)
}

// WebDocumentNoProxy represents TL type `webDocumentNoProxy#f9c8bcc6`.
// Remote document that can be downloaded without proxying through telegram¹
//
// Links:
//  1. https://core.telegram.org/api/files
//
// See https://core.telegram.org/constructor/webDocumentNoProxy for reference.
type WebDocumentNoProxy struct {
	// Document URL
	URL string
	// File size
	Size int
	// MIME type
	MimeType string
	// Attributes for media types
	Attributes []DocumentAttributeClass
}

// WebDocumentNoProxyTypeID is TL type id of WebDocumentNoProxy.
const WebDocumentNoProxyTypeID = 0xf9c8bcc6

// construct implements constructor of WebDocumentClass.
func ( WebDocumentNoProxy) () WebDocumentClass { return & }

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

	_ WebDocumentClass = &WebDocumentNoProxy{}
)

func ( *WebDocumentNoProxy) () bool {
	if  == nil {
		return true
	}
	if !(.URL == "") {
		return false
	}
	if !(.Size == 0) {
		return false
	}
	if !(.MimeType == "") {
		return false
	}
	if !(.Attributes == nil) {
		return false
	}

	return true
}

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

// FillFrom fills WebDocumentNoProxy from given interface.
func ( *WebDocumentNoProxy) ( interface {
	() ( string)
	() ( int)
	() ( string)
	() ( []DocumentAttributeClass)
}) {
	.URL = .()
	.Size = .()
	.MimeType = .()
	.Attributes = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *WebDocumentNoProxy) () tdp.Type {
	 := tdp.Type{
		Name: "webDocumentNoProxy",
		ID:   WebDocumentNoProxyTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "Size",
			SchemaName: "size",
		},
		{
			Name:       "MimeType",
			SchemaName: "mime_type",
		},
		{
			Name:       "Attributes",
			SchemaName: "attributes",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *WebDocumentNoProxy) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode webDocumentNoProxy#f9c8bcc6 as nil")
	}
	.PutID(WebDocumentNoProxyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *WebDocumentNoProxy) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode webDocumentNoProxy#f9c8bcc6 as nil")
	}
	.PutString(.URL)
	.PutInt(.Size)
	.PutString(.MimeType)
	.PutVectorHeader(len(.Attributes))
	for ,  := range .Attributes {
		if  == nil {
			return fmt.Errorf("unable to encode webDocumentNoProxy#f9c8bcc6: field attributes element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode webDocumentNoProxy#f9c8bcc6: field attributes element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *WebDocumentNoProxy) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode webDocumentNoProxy#f9c8bcc6 to nil")
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode webDocumentNoProxy#f9c8bcc6: field url: %w", )
		}
		.URL = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode webDocumentNoProxy#f9c8bcc6: field size: %w", )
		}
		.Size = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode webDocumentNoProxy#f9c8bcc6: field mime_type: %w", )
		}
		.MimeType = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode webDocumentNoProxy#f9c8bcc6: field attributes: %w", )
		}

		if  > 0 {
			.Attributes = make([]DocumentAttributeClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeDocumentAttribute()
			if  != nil {
				return fmt.Errorf("unable to decode webDocumentNoProxy#f9c8bcc6: field attributes: %w", )
			}
			.Attributes = append(.Attributes, )
		}
	}
	return nil
}

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

// GetSize returns value of Size field.
func ( *WebDocumentNoProxy) () ( int) {
	if  == nil {
		return
	}
	return .Size
}

// GetMimeType returns value of MimeType field.
func ( *WebDocumentNoProxy) () ( string) {
	if  == nil {
		return
	}
	return .MimeType
}

// GetAttributes returns value of Attributes field.
func ( *WebDocumentNoProxy) () ( []DocumentAttributeClass) {
	if  == nil {
		return
	}
	return .Attributes
}

// MapAttributes returns field Attributes wrapped in DocumentAttributeClassArray helper.
func ( *WebDocumentNoProxy) () ( DocumentAttributeClassArray) {
	return DocumentAttributeClassArray(.Attributes)
}

// WebDocumentClassName is schema name of WebDocumentClass.
const WebDocumentClassName = "WebDocument"

// WebDocumentClass represents WebDocument generic type.
//
// See https://core.telegram.org/type/WebDocument for reference.
//
// Example:
//
//	g, err := tg.DecodeWebDocument(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.WebDocument: // webDocument#1c570ed1
//	case *tg.WebDocumentNoProxy: // webDocumentNoProxy#f9c8bcc6
//	default: panic(v)
//	}
type WebDocumentClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() WebDocumentClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// Document URL
	GetURL() (value string)

	// File size
	GetSize() (value int)

	// MIME type
	GetMimeType() (value string)

	// Attributes for media types
	GetAttributes() (value []DocumentAttributeClass)
	// Attributes for media types
	MapAttributes() (value DocumentAttributeClassArray)
}

// AsInput tries to map WebDocument to InputWebDocument.
func ( *WebDocument) () *InputWebDocument {
	 := new(InputWebDocument)
	.URL = .GetURL()
	.Size = .GetSize()
	.MimeType = .GetMimeType()
	.Attributes = .GetAttributes()

	return 
}

// DecodeWebDocument implements binary de-serialization for WebDocumentClass.
func ( *bin.Buffer) (WebDocumentClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case WebDocumentTypeID:
		// Decoding webDocument#1c570ed1.
		 := WebDocument{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode WebDocumentClass: %w", )
		}
		return &, nil
	case WebDocumentNoProxyTypeID:
		// Decoding webDocumentNoProxy#f9c8bcc6.
		 := WebDocumentNoProxy{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode WebDocumentClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode WebDocumentClass: %w", bin.NewUnexpectedID())
	}
}

// WebDocument boxes the WebDocumentClass providing a helper.
type WebDocumentBox struct {
	WebDocument WebDocumentClass
}

// Decode implements bin.Decoder for WebDocumentBox.
func ( *WebDocumentBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode WebDocumentBox to nil")
	}
	,  := DecodeWebDocument()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.WebDocument = 
	return nil
}

// Encode implements bin.Encode for WebDocumentBox.
func ( *WebDocumentBox) ( *bin.Buffer) error {
	if  == nil || .WebDocument == nil {
		return fmt.Errorf("unable to encode WebDocumentClass as nil")
	}
	return .WebDocument.Encode()
}