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

// UserProfilePhotoEmpty represents TL type `userProfilePhotoEmpty#4f11bae1`.
// Profile photo has not been set, or was hidden.
//
// See https://core.telegram.org/constructor/userProfilePhotoEmpty for reference.
type UserProfilePhotoEmpty struct {
}

// UserProfilePhotoEmptyTypeID is TL type id of UserProfilePhotoEmpty.
const UserProfilePhotoEmptyTypeID = 0x4f11bae1

// construct implements constructor of UserProfilePhotoClass.
func ( UserProfilePhotoEmpty) () UserProfilePhotoClass { return & }

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

	_ UserProfilePhotoClass = &UserProfilePhotoEmpty{}
)

func ( *UserProfilePhotoEmpty) () bool {
	if  == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func ( *UserProfilePhotoEmpty) () tdp.Type {
	 := tdp.Type{
		Name: "userProfilePhotoEmpty",
		ID:   UserProfilePhotoEmptyTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{}
	return 
}

// Encode implements bin.Encoder.
func ( *UserProfilePhotoEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode userProfilePhotoEmpty#4f11bae1 as nil")
	}
	.PutID(UserProfilePhotoEmptyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UserProfilePhotoEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode userProfilePhotoEmpty#4f11bae1 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *UserProfilePhotoEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode userProfilePhotoEmpty#4f11bae1 to nil")
	}
	return nil
}

// UserProfilePhoto represents TL type `userProfilePhoto#82d1f706`.
// User profile photo.
//
// See https://core.telegram.org/constructor/userProfilePhoto for reference.
type UserProfilePhoto struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether an animated profile picture¹ is available for this user
	//
	// Links:
	//  1) https://core.telegram.org/api/files#animated-profile-pictures
	HasVideo bool
	// Whether this profile photo is only visible to us (i.e. it was set using photos
	// uploadContactProfilePhoto¹).
	//
	// Links:
	//  1) https://core.telegram.org/method/photos.uploadContactProfilePhoto
	Personal bool
	// Identifier of the respective photo
	PhotoID int64
	// Stripped thumbnail¹
	//
	// Links:
	//  1) https://core.telegram.org/api/files#stripped-thumbnails
	//
	// Use SetStrippedThumb and GetStrippedThumb helpers.
	StrippedThumb []byte
	// DC ID where the photo is stored
	DCID int
}

// UserProfilePhotoTypeID is TL type id of UserProfilePhoto.
const UserProfilePhotoTypeID = 0x82d1f706

// construct implements constructor of UserProfilePhotoClass.
func ( UserProfilePhoto) () UserProfilePhotoClass { return & }

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

	_ UserProfilePhotoClass = &UserProfilePhoto{}
)

func ( *UserProfilePhoto) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.HasVideo == false) {
		return false
	}
	if !(.Personal == false) {
		return false
	}
	if !(.PhotoID == 0) {
		return false
	}
	if !(.StrippedThumb == nil) {
		return false
	}
	if !(.DCID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills UserProfilePhoto from given interface.
func ( *UserProfilePhoto) ( interface {
	() ( bool)
	() ( bool)
	() ( int64)
	() ( []byte,  bool)
	() ( int)
}) {
	.HasVideo = .()
	.Personal = .()
	.PhotoID = .()
	if ,  := .();  {
		.StrippedThumb = 
	}

	.DCID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *UserProfilePhoto) () tdp.Type {
	 := tdp.Type{
		Name: "userProfilePhoto",
		ID:   UserProfilePhotoTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "HasVideo",
			SchemaName: "has_video",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Personal",
			SchemaName: "personal",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "PhotoID",
			SchemaName: "photo_id",
		},
		{
			Name:       "StrippedThumb",
			SchemaName: "stripped_thumb",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "DCID",
			SchemaName: "dc_id",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *UserProfilePhoto) () {
	if !(.HasVideo == false) {
		.Flags.Set(0)
	}
	if !(.Personal == false) {
		.Flags.Set(2)
	}
	if !(.StrippedThumb == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *UserProfilePhoto) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode userProfilePhoto#82d1f706 as nil")
	}
	.PutID(UserProfilePhotoTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UserProfilePhoto) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode userProfilePhoto#82d1f706 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode userProfilePhoto#82d1f706: field flags: %w", )
	}
	.PutLong(.PhotoID)
	if .Flags.Has(1) {
		.PutBytes(.StrippedThumb)
	}
	.PutInt(.DCID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *UserProfilePhoto) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode userProfilePhoto#82d1f706 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode userProfilePhoto#82d1f706: field flags: %w", )
		}
	}
	.HasVideo = .Flags.Has(0)
	.Personal = .Flags.Has(2)
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode userProfilePhoto#82d1f706: field photo_id: %w", )
		}
		.PhotoID = 
	}
	if .Flags.Has(1) {
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode userProfilePhoto#82d1f706: field stripped_thumb: %w", )
		}
		.StrippedThumb = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode userProfilePhoto#82d1f706: field dc_id: %w", )
		}
		.DCID = 
	}
	return nil
}

// SetHasVideo sets value of HasVideo conditional field.
func ( *UserProfilePhoto) ( bool) {
	if  {
		.Flags.Set(0)
		.HasVideo = true
	} else {
		.Flags.Unset(0)
		.HasVideo = false
	}
}

// GetHasVideo returns value of HasVideo conditional field.
func ( *UserProfilePhoto) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetPersonal sets value of Personal conditional field.
func ( *UserProfilePhoto) ( bool) {
	if  {
		.Flags.Set(2)
		.Personal = true
	} else {
		.Flags.Unset(2)
		.Personal = false
	}
}

// GetPersonal returns value of Personal conditional field.
func ( *UserProfilePhoto) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// GetPhotoID returns value of PhotoID field.
func ( *UserProfilePhoto) () ( int64) {
	if  == nil {
		return
	}
	return .PhotoID
}

// SetStrippedThumb sets value of StrippedThumb conditional field.
func ( *UserProfilePhoto) ( []byte) {
	.Flags.Set(1)
	.StrippedThumb = 
}

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

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

// UserProfilePhotoClassName is schema name of UserProfilePhotoClass.
const UserProfilePhotoClassName = "UserProfilePhoto"

// UserProfilePhotoClass represents UserProfilePhoto generic type.
//
// See https://core.telegram.org/type/UserProfilePhoto for reference.
//
// Example:
//
//	g, err := tg.DecodeUserProfilePhoto(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.UserProfilePhotoEmpty: // userProfilePhotoEmpty#4f11bae1
//	case *tg.UserProfilePhoto: // userProfilePhoto#82d1f706
//	default: panic(v)
//	}
type UserProfilePhotoClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() UserProfilePhotoClass

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

	// AsNotEmpty tries to map UserProfilePhotoClass to UserProfilePhoto.
	AsNotEmpty() (*UserProfilePhoto, bool)
}

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

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

// DecodeUserProfilePhoto implements binary de-serialization for UserProfilePhotoClass.
func ( *bin.Buffer) (UserProfilePhotoClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case UserProfilePhotoEmptyTypeID:
		// Decoding userProfilePhotoEmpty#4f11bae1.
		 := UserProfilePhotoEmpty{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode UserProfilePhotoClass: %w", )
		}
		return &, nil
	case UserProfilePhotoTypeID:
		// Decoding userProfilePhoto#82d1f706.
		 := UserProfilePhoto{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode UserProfilePhotoClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode UserProfilePhotoClass: %w", bin.NewUnexpectedID())
	}
}

// UserProfilePhoto boxes the UserProfilePhotoClass providing a helper.
type UserProfilePhotoBox struct {
	UserProfilePhoto UserProfilePhotoClass
}

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

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