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

// PhotoEmpty represents TL type `photoEmpty#2331b22d`.
// Empty constructor, non-existent photo
//
// See https://core.telegram.org/constructor/photoEmpty for reference.
type PhotoEmpty struct {
	// Photo identifier
	ID int64
}

// PhotoEmptyTypeID is TL type id of PhotoEmpty.
const PhotoEmptyTypeID = 0x2331b22d

// construct implements constructor of PhotoClass.
func ( PhotoEmpty) () PhotoClass { return & }

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

	_ PhotoClass = &PhotoEmpty{}
)

func ( *PhotoEmpty) () bool {
	if  == nil {
		return true
	}
	if !(.ID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills PhotoEmpty from given interface.
func ( *PhotoEmpty) ( interface {
	() ( int64)
}) {
	.ID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PhotoEmpty) () tdp.Type {
	 := tdp.Type{
		Name: "photoEmpty",
		ID:   PhotoEmptyTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *PhotoEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode photoEmpty#2331b22d as nil")
	}
	.PutID(PhotoEmptyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PhotoEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode photoEmpty#2331b22d as nil")
	}
	.PutLong(.ID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PhotoEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode photoEmpty#2331b22d to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode photoEmpty#2331b22d: field id: %w", )
		}
		.ID = 
	}
	return nil
}

// GetID returns value of ID field.
func ( *PhotoEmpty) () ( int64) {
	if  == nil {
		return
	}
	return .ID
}

// Photo represents TL type `photo#fb197a65`.
// Photo
//
// See https://core.telegram.org/constructor/photo for reference.
type Photo struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the photo has mask stickers attached to it
	HasStickers bool
	// ID
	ID int64
	// Access hash
	AccessHash int64
	// file referenceĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/api/file_reference
	FileReference []byte
	// Date of upload
	Date int
	// Available sizes for download
	Sizes []PhotoSizeClass
	// For animated profilesĀ¹, the MPEG4 videos
	//
	// Links:
	//  1) https://core.telegram.org/api/files#animated-profile-pictures
	//
	// Use SetVideoSizes and GetVideoSizes helpers.
	VideoSizes []VideoSizeClass
	// DC ID to use for download
	DCID int
}

// PhotoTypeID is TL type id of Photo.
const PhotoTypeID = 0xfb197a65

// construct implements constructor of PhotoClass.
func ( Photo) () PhotoClass { return & }

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

	_ PhotoClass = &Photo{}
)

func ( *Photo) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.HasStickers == false) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.AccessHash == 0) {
		return false
	}
	if !(.FileReference == nil) {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.Sizes == nil) {
		return false
	}
	if !(.VideoSizes == nil) {
		return false
	}
	if !(.DCID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills Photo from given interface.
func ( *Photo) ( interface {
	() ( bool)
	() ( int64)
	() ( int64)
	() ( []byte)
	() ( int)
	() ( []PhotoSizeClass)
	() ( []VideoSizeClass,  bool)
	() ( int)
}) {
	.HasStickers = .()
	.ID = .()
	.AccessHash = .()
	.FileReference = .()
	.Date = .()
	.Sizes = .()
	if ,  := .();  {
		.VideoSizes = 
	}

	.DCID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *Photo) () tdp.Type {
	 := tdp.Type{
		Name: "photo",
		ID:   PhotoTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "HasStickers",
			SchemaName: "has_stickers",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "AccessHash",
			SchemaName: "access_hash",
		},
		{
			Name:       "FileReference",
			SchemaName: "file_reference",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Sizes",
			SchemaName: "sizes",
		},
		{
			Name:       "VideoSizes",
			SchemaName: "video_sizes",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "DCID",
			SchemaName: "dc_id",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *Photo) () {
	if !(.HasStickers == false) {
		.Flags.Set(0)
	}
	if !(.VideoSizes == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *Photo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode photo#fb197a65 as nil")
	}
	.PutID(PhotoTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *Photo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode photo#fb197a65 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode photo#fb197a65: field flags: %w", )
	}
	.PutLong(.ID)
	.PutLong(.AccessHash)
	.PutBytes(.FileReference)
	.PutInt(.Date)
	.PutVectorHeader(len(.Sizes))
	for ,  := range .Sizes {
		if  == nil {
			return fmt.Errorf("unable to encode photo#fb197a65: field sizes element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode photo#fb197a65: field sizes element with index %d: %w", , )
		}
	}
	if .Flags.Has(1) {
		.PutVectorHeader(len(.VideoSizes))
		for ,  := range .VideoSizes {
			if  == nil {
				return fmt.Errorf("unable to encode photo#fb197a65: field video_sizes element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode photo#fb197a65: field video_sizes element with index %d: %w", , )
			}
		}
	}
	.PutInt(.DCID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *Photo) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode photo#fb197a65 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode photo#fb197a65: field flags: %w", )
		}
	}
	.HasStickers = .Flags.Has(0)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode photo#fb197a65: field id: %w", )
		}
		.ID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode photo#fb197a65: field access_hash: %w", )
		}
		.AccessHash = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode photo#fb197a65: field file_reference: %w", )
		}
		.FileReference = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode photo#fb197a65: field date: %w", )
		}
		.Date = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode photo#fb197a65: field sizes: %w", )
		}

		if  > 0 {
			.Sizes = make([]PhotoSizeClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePhotoSize()
			if  != nil {
				return fmt.Errorf("unable to decode photo#fb197a65: field sizes: %w", )
			}
			.Sizes = append(.Sizes, )
		}
	}
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode photo#fb197a65: field video_sizes: %w", )
		}

		if  > 0 {
			.VideoSizes = make([]VideoSizeClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeVideoSize()
			if  != nil {
				return fmt.Errorf("unable to decode photo#fb197a65: field video_sizes: %w", )
			}
			.VideoSizes = append(.VideoSizes, )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode photo#fb197a65: field dc_id: %w", )
		}
		.DCID = 
	}
	return nil
}

// SetHasStickers sets value of HasStickers conditional field.
func ( *Photo) ( bool) {
	if  {
		.Flags.Set(0)
		.HasStickers = true
	} else {
		.Flags.Unset(0)
		.HasStickers = false
	}
}

// GetHasStickers returns value of HasStickers conditional field.
func ( *Photo) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetID returns value of ID field.
func ( *Photo) () ( int64) {
	if  == nil {
		return
	}
	return .ID
}

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

// GetFileReference returns value of FileReference field.
func ( *Photo) () ( []byte) {
	if  == nil {
		return
	}
	return .FileReference
}

// GetDate returns value of Date field.
func ( *Photo) () ( int) {
	if  == nil {
		return
	}
	return .Date
}

// GetSizes returns value of Sizes field.
func ( *Photo) () ( []PhotoSizeClass) {
	if  == nil {
		return
	}
	return .Sizes
}

// SetVideoSizes sets value of VideoSizes conditional field.
func ( *Photo) ( []VideoSizeClass) {
	.Flags.Set(1)
	.VideoSizes = 
}

// GetVideoSizes returns value of VideoSizes conditional field and
// boolean which is true if field was set.
func ( *Photo) () ( []VideoSizeClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .VideoSizes, true
}

// GetDCID returns value of DCID field.
func ( *Photo) () ( int) {
	if  == nil {
		return
	}
	return .DCID
}

// MapSizes returns field Sizes wrapped in PhotoSizeClassArray helper.
func ( *Photo) () ( PhotoSizeClassArray) {
	return PhotoSizeClassArray(.Sizes)
}

// MapVideoSizes returns field VideoSizes wrapped in VideoSizeClassArray helper.
func ( *Photo) () ( VideoSizeClassArray,  bool) {
	if !.Flags.Has(1) {
		return , false
	}
	return VideoSizeClassArray(.VideoSizes), true
}

// PhotoClassName is schema name of PhotoClass.
const PhotoClassName = "Photo"

// PhotoClass represents Photo generic type.
//
// See https://core.telegram.org/type/Photo for reference.
//
// Example:
//
//	g, err := tg.DecodePhoto(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.PhotoEmpty: // photoEmpty#2331b22d
//	case *tg.Photo: // photo#fb197a65
//	default: panic(v)
//	}
type PhotoClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() PhotoClass

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

	// Photo identifier
	GetID() (value int64)

	// AsNotEmpty tries to map PhotoClass to Photo.
	AsNotEmpty() (*Photo, bool)
}

// AsInput tries to map Photo to InputPhoto.
func ( *Photo) () *InputPhoto {
	 := new(InputPhoto)
	.ID = .GetID()
	.AccessHash = .GetAccessHash()
	.FileReference = .GetFileReference()

	return 
}

// AsNotEmpty tries to map PhotoEmpty to Photo.
func ( *PhotoEmpty) () (*Photo, bool) {
	return nil, false
}

// AsNotEmpty tries to map Photo to Photo.
func ( *Photo) () (*Photo, bool) {
	return , true
}

// DecodePhoto implements binary de-serialization for PhotoClass.
func ( *bin.Buffer) (PhotoClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case PhotoEmptyTypeID:
		// Decoding photoEmpty#2331b22d.
		 := PhotoEmpty{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PhotoClass: %w", )
		}
		return &, nil
	case PhotoTypeID:
		// Decoding photo#fb197a65.
		 := Photo{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode PhotoClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode PhotoClass: %w", bin.NewUnexpectedID())
	}
}

// Photo boxes the PhotoClass providing a helper.
type PhotoBox struct {
	Photo PhotoClass
}

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

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