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

// InputSingleMedia represents TL type `inputSingleMedia#1cc6e91f`.
// A single media in an album or grouped media¹ sent with messages.sendMultiMedia².
//
// Links:
//  1. https://core.telegram.org/api/files#albums-grouped-media
//  2. https://core.telegram.org/method/messages.sendMultiMedia
//
// See https://core.telegram.org/constructor/inputSingleMedia for reference.
type InputSingleMedia struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// The media
	Media InputMediaClass
	// Unique client media ID required to prevent message resending
	RandomID int64
	// A caption for the media
	Message string
	// Message entities¹ for styled text
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	//
	// Use SetEntities and GetEntities helpers.
	Entities []MessageEntityClass
}

// InputSingleMediaTypeID is TL type id of InputSingleMedia.
const InputSingleMediaTypeID = 0x1cc6e91f

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

func ( *InputSingleMedia) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Media == nil) {
		return false
	}
	if !(.RandomID == 0) {
		return false
	}
	if !(.Message == "") {
		return false
	}
	if !(.Entities == nil) {
		return false
	}

	return true
}

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

// FillFrom fills InputSingleMedia from given interface.
func ( *InputSingleMedia) ( interface {
	() ( InputMediaClass)
	() ( int64)
	() ( string)
	() ( []MessageEntityClass,  bool)
}) {
	.Media = .()
	.RandomID = .()
	.Message = .()
	if ,  := .();  {
		.Entities = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *InputSingleMedia) () tdp.Type {
	 := tdp.Type{
		Name: "inputSingleMedia",
		ID:   InputSingleMediaTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Media",
			SchemaName: "media",
		},
		{
			Name:       "RandomID",
			SchemaName: "random_id",
		},
		{
			Name:       "Message",
			SchemaName: "message",
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *InputSingleMedia) () {
	if !(.Entities == nil) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *InputSingleMedia) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode inputSingleMedia#1cc6e91f as nil")
	}
	.PutID(InputSingleMediaTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *InputSingleMedia) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode inputSingleMedia#1cc6e91f as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode inputSingleMedia#1cc6e91f: field flags: %w", )
	}
	if .Media == nil {
		return fmt.Errorf("unable to encode inputSingleMedia#1cc6e91f: field media is nil")
	}
	if  := .Media.Encode();  != nil {
		return fmt.Errorf("unable to encode inputSingleMedia#1cc6e91f: field media: %w", )
	}
	.PutLong(.RandomID)
	.PutString(.Message)
	if .Flags.Has(0) {
		.PutVectorHeader(len(.Entities))
		for ,  := range .Entities {
			if  == nil {
				return fmt.Errorf("unable to encode inputSingleMedia#1cc6e91f: field entities element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode inputSingleMedia#1cc6e91f: field entities element with index %d: %w", , )
			}
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *InputSingleMedia) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode inputSingleMedia#1cc6e91f to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field flags: %w", )
		}
	}
	{
		,  := DecodeInputMedia()
		if  != nil {
			return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field media: %w", )
		}
		.Media = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field random_id: %w", )
		}
		.RandomID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field message: %w", )
		}
		.Message = 
	}
	if .Flags.Has(0) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field entities: %w", )
		}

		if  > 0 {
			.Entities = make([]MessageEntityClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessageEntity()
			if  != nil {
				return fmt.Errorf("unable to decode inputSingleMedia#1cc6e91f: field entities: %w", )
			}
			.Entities = append(.Entities, )
		}
	}
	return nil
}

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

// GetRandomID returns value of RandomID field.
func ( *InputSingleMedia) () ( int64) {
	if  == nil {
		return
	}
	return .RandomID
}

// GetMessage returns value of Message field.
func ( *InputSingleMedia) () ( string) {
	if  == nil {
		return
	}
	return .Message
}

// SetEntities sets value of Entities conditional field.
func ( *InputSingleMedia) ( []MessageEntityClass) {
	.Flags.Set(0)
	.Entities = 
}

// GetEntities returns value of Entities conditional field and
// boolean which is true if field was set.
func ( *InputSingleMedia) () ( []MessageEntityClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Entities, true
}

// MapEntities returns field Entities wrapped in MessageEntityClassArray helper.
func ( *InputSingleMedia) () ( MessageEntityClassArray,  bool) {
	if !.Flags.Has(0) {
		return , false
	}
	return MessageEntityClassArray(.Entities), true
}