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

// MessageExtendedMediaPreview represents TL type `messageExtendedMediaPreview#ad628cc8`.
// Extended media preview
//
// See https://core.telegram.org/constructor/messageExtendedMediaPreview for reference.
type MessageExtendedMediaPreview struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Width
	//
	// Use SetW and GetW helpers.
	W int
	// Height
	//
	// Use SetH and GetH helpers.
	H int
	// Thumbnail
	//
	// Use SetThumb and GetThumb helpers.
	Thumb PhotoSizeClass
	// Video duration
	//
	// Use SetVideoDuration and GetVideoDuration helpers.
	VideoDuration int
}

// MessageExtendedMediaPreviewTypeID is TL type id of MessageExtendedMediaPreview.
const MessageExtendedMediaPreviewTypeID = 0xad628cc8

// construct implements constructor of MessageExtendedMediaClass.
func ( MessageExtendedMediaPreview) () MessageExtendedMediaClass { return & }

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

	_ MessageExtendedMediaClass = &MessageExtendedMediaPreview{}
)

func ( *MessageExtendedMediaPreview) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.W == 0) {
		return false
	}
	if !(.H == 0) {
		return false
	}
	if !(.Thumb == nil) {
		return false
	}
	if !(.VideoDuration == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessageExtendedMediaPreview from given interface.
func ( *MessageExtendedMediaPreview) ( interface {
	() ( int,  bool)
	() ( int,  bool)
	() ( PhotoSizeClass,  bool)
	() ( int,  bool)
}) {
	if ,  := .();  {
		.W = 
	}

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *MessageExtendedMediaPreview) () tdp.Type {
	 := tdp.Type{
		Name: "messageExtendedMediaPreview",
		ID:   MessageExtendedMediaPreviewTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "W",
			SchemaName: "w",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "H",
			SchemaName: "h",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Thumb",
			SchemaName: "thumb",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "VideoDuration",
			SchemaName: "video_duration",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessageExtendedMediaPreview) () {
	if !(.W == 0) {
		.Flags.Set(0)
	}
	if !(.H == 0) {
		.Flags.Set(0)
	}
	if !(.Thumb == nil) {
		.Flags.Set(1)
	}
	if !(.VideoDuration == 0) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *MessageExtendedMediaPreview) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageExtendedMediaPreview#ad628cc8 as nil")
	}
	.PutID(MessageExtendedMediaPreviewTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessageExtendedMediaPreview) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageExtendedMediaPreview#ad628cc8 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messageExtendedMediaPreview#ad628cc8: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutInt(.W)
	}
	if .Flags.Has(0) {
		.PutInt(.H)
	}
	if .Flags.Has(1) {
		if .Thumb == nil {
			return fmt.Errorf("unable to encode messageExtendedMediaPreview#ad628cc8: field thumb is nil")
		}
		if  := .Thumb.Encode();  != nil {
			return fmt.Errorf("unable to encode messageExtendedMediaPreview#ad628cc8: field thumb: %w", )
		}
	}
	if .Flags.Has(2) {
		.PutInt(.VideoDuration)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessageExtendedMediaPreview) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messageExtendedMediaPreview#ad628cc8 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messageExtendedMediaPreview#ad628cc8: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageExtendedMediaPreview#ad628cc8: field w: %w", )
		}
		.W = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageExtendedMediaPreview#ad628cc8: field h: %w", )
		}
		.H = 
	}
	if .Flags.Has(1) {
		,  := DecodePhotoSize()
		if  != nil {
			return fmt.Errorf("unable to decode messageExtendedMediaPreview#ad628cc8: field thumb: %w", )
		}
		.Thumb = 
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageExtendedMediaPreview#ad628cc8: field video_duration: %w", )
		}
		.VideoDuration = 
	}
	return nil
}

// SetW sets value of W conditional field.
func ( *MessageExtendedMediaPreview) ( int) {
	.Flags.Set(0)
	.W = 
}

// GetW returns value of W conditional field and
// boolean which is true if field was set.
func ( *MessageExtendedMediaPreview) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .W, true
}

// SetH sets value of H conditional field.
func ( *MessageExtendedMediaPreview) ( int) {
	.Flags.Set(0)
	.H = 
}

// GetH returns value of H conditional field and
// boolean which is true if field was set.
func ( *MessageExtendedMediaPreview) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .H, true
}

// SetThumb sets value of Thumb conditional field.
func ( *MessageExtendedMediaPreview) ( PhotoSizeClass) {
	.Flags.Set(1)
	.Thumb = 
}

// GetThumb returns value of Thumb conditional field and
// boolean which is true if field was set.
func ( *MessageExtendedMediaPreview) () ( PhotoSizeClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Thumb, true
}

// SetVideoDuration sets value of VideoDuration conditional field.
func ( *MessageExtendedMediaPreview) ( int) {
	.Flags.Set(2)
	.VideoDuration = 
}

// GetVideoDuration returns value of VideoDuration conditional field and
// boolean which is true if field was set.
func ( *MessageExtendedMediaPreview) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .VideoDuration, true
}

// MessageExtendedMedia represents TL type `messageExtendedMedia#ee479c64`.
// Extended media
//
// See https://core.telegram.org/constructor/messageExtendedMedia for reference.
type MessageExtendedMedia struct {
	// Media
	Media MessageMediaClass
}

// MessageExtendedMediaTypeID is TL type id of MessageExtendedMedia.
const MessageExtendedMediaTypeID = 0xee479c64

// construct implements constructor of MessageExtendedMediaClass.
func ( MessageExtendedMedia) () MessageExtendedMediaClass { return & }

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

	_ MessageExtendedMediaClass = &MessageExtendedMedia{}
)

func ( *MessageExtendedMedia) () bool {
	if  == nil {
		return true
	}
	if !(.Media == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessageExtendedMedia from given interface.
func ( *MessageExtendedMedia) ( interface {
	() ( MessageMediaClass)
}) {
	.Media = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessageExtendedMedia) () tdp.Type {
	 := tdp.Type{
		Name: "messageExtendedMedia",
		ID:   MessageExtendedMediaTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Media",
			SchemaName: "media",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *MessageExtendedMedia) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageExtendedMedia#ee479c64 as nil")
	}
	.PutID(MessageExtendedMediaTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessageExtendedMedia) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageExtendedMedia#ee479c64 as nil")
	}
	if .Media == nil {
		return fmt.Errorf("unable to encode messageExtendedMedia#ee479c64: field media is nil")
	}
	if  := .Media.Encode();  != nil {
		return fmt.Errorf("unable to encode messageExtendedMedia#ee479c64: field media: %w", )
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessageExtendedMedia) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messageExtendedMedia#ee479c64 to nil")
	}
	{
		,  := DecodeMessageMedia()
		if  != nil {
			return fmt.Errorf("unable to decode messageExtendedMedia#ee479c64: field media: %w", )
		}
		.Media = 
	}
	return nil
}

// GetMedia returns value of Media field.
func ( *MessageExtendedMedia) () ( MessageMediaClass) {
	if  == nil {
		return
	}
	return .Media
}

// MessageExtendedMediaClassName is schema name of MessageExtendedMediaClass.
const MessageExtendedMediaClassName = "MessageExtendedMedia"

// MessageExtendedMediaClass represents MessageExtendedMedia generic type.
//
// See https://core.telegram.org/type/MessageExtendedMedia for reference.
//
// Example:
//
//	g, err := tg.DecodeMessageExtendedMedia(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.MessageExtendedMediaPreview: // messageExtendedMediaPreview#ad628cc8
//	case *tg.MessageExtendedMedia: // messageExtendedMedia#ee479c64
//	default: panic(v)
//	}
type MessageExtendedMediaClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() MessageExtendedMediaClass

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

// DecodeMessageExtendedMedia implements binary de-serialization for MessageExtendedMediaClass.
func ( *bin.Buffer) (MessageExtendedMediaClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case MessageExtendedMediaPreviewTypeID:
		// Decoding messageExtendedMediaPreview#ad628cc8.
		 := MessageExtendedMediaPreview{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode MessageExtendedMediaClass: %w", )
		}
		return &, nil
	case MessageExtendedMediaTypeID:
		// Decoding messageExtendedMedia#ee479c64.
		 := MessageExtendedMedia{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode MessageExtendedMediaClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode MessageExtendedMediaClass: %w", bin.NewUnexpectedID())
	}
}

// MessageExtendedMedia boxes the MessageExtendedMediaClass providing a helper.
type MessageExtendedMediaBox struct {
	MessageExtendedMedia MessageExtendedMediaClass
}

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

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