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

// MessagesGetDocumentByHashRequest represents TL type `messages.getDocumentByHash#b1f2061f`.
// Get a document by its SHA256 hash, mainly used for gifs
//
// See https://core.telegram.org/method/messages.getDocumentByHash for reference.
type MessagesGetDocumentByHashRequest struct {
	// SHA256 of file
	SHA256 []byte
	// Size of the file in bytes
	Size int64
	// Mime type
	MimeType string
}

// MessagesGetDocumentByHashRequestTypeID is TL type id of MessagesGetDocumentByHashRequest.
const MessagesGetDocumentByHashRequestTypeID = 0xb1f2061f

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

func ( *MessagesGetDocumentByHashRequest) () bool {
	if  == nil {
		return true
	}
	if !(.SHA256 == nil) {
		return false
	}
	if !(.Size == 0) {
		return false
	}
	if !(.MimeType == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesGetDocumentByHashRequest from given interface.
func ( *MessagesGetDocumentByHashRequest) ( interface {
	() ( []byte)
	() ( int64)
	() ( string)
}) {
	.SHA256 = .()
	.Size = .()
	.MimeType = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesGetDocumentByHashRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.getDocumentByHash",
		ID:   MessagesGetDocumentByHashRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "SHA256",
			SchemaName: "sha256",
		},
		{
			Name:       "Size",
			SchemaName: "size",
		},
		{
			Name:       "MimeType",
			SchemaName: "mime_type",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *MessagesGetDocumentByHashRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.getDocumentByHash#b1f2061f as nil")
	}
	.PutID(MessagesGetDocumentByHashRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesGetDocumentByHashRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.getDocumentByHash#b1f2061f as nil")
	}
	.PutBytes(.SHA256)
	.PutLong(.Size)
	.PutString(.MimeType)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesGetDocumentByHashRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.getDocumentByHash#b1f2061f to nil")
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getDocumentByHash#b1f2061f: field sha256: %w", )
		}
		.SHA256 = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getDocumentByHash#b1f2061f: field size: %w", )
		}
		.Size = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.getDocumentByHash#b1f2061f: field mime_type: %w", )
		}
		.MimeType = 
	}
	return nil
}

// GetSHA256 returns value of SHA256 field.
func ( *MessagesGetDocumentByHashRequest) () ( []byte) {
	if  == nil {
		return
	}
	return .SHA256
}

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

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

// MessagesGetDocumentByHash invokes method messages.getDocumentByHash#b1f2061f returning error if any.
// Get a document by its SHA256 hash, mainly used for gifs
//
// Possible errors:
//
//	400 SHA256_HASH_INVALID: The provided SHA256 hash is invalid.
//
// See https://core.telegram.org/method/messages.getDocumentByHash for reference.
// Can be used by bots.
func ( *Client) ( context.Context,  *MessagesGetDocumentByHashRequest) (DocumentClass, error) {
	var  DocumentBox

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