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

// ChatPhotoEmpty represents TL type `chatPhotoEmpty#37c1011c`.
// Group photo is not set.
//
// See https://core.telegram.org/constructor/chatPhotoEmpty for reference.
type ChatPhotoEmpty struct {
}

// ChatPhotoEmptyTypeID is TL type id of ChatPhotoEmpty.
const ChatPhotoEmptyTypeID = 0x37c1011c

// construct implements constructor of ChatPhotoClass.
func ( ChatPhotoEmpty) () ChatPhotoClass { return & }

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

	_ ChatPhotoClass = &ChatPhotoEmpty{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func ( *ChatPhotoEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatPhotoEmpty#37c1011c as nil")
	}
	.PutID(ChatPhotoEmptyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChatPhotoEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatPhotoEmpty#37c1011c as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *ChatPhotoEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatPhotoEmpty#37c1011c to nil")
	}
	return nil
}

// ChatPhoto represents TL type `chatPhoto#1c6e1c11`.
// Group profile photo.
//
// See https://core.telegram.org/constructor/chatPhoto for reference.
type ChatPhoto struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the user has an animated profile picture
	HasVideo bool
	// Photo ID
	PhotoID int64
	// Stripped thumbnail¹
	//
	// Links:
	//  1) https://core.telegram.org/api/files#stripped-thumbnails
	//
	// Use SetStrippedThumb and GetStrippedThumb helpers.
	StrippedThumb []byte
	// DC where this photo is stored
	DCID int
}

// ChatPhotoTypeID is TL type id of ChatPhoto.
const ChatPhotoTypeID = 0x1c6e1c11

// construct implements constructor of ChatPhotoClass.
func ( ChatPhoto) () ChatPhotoClass { return & }

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

	_ ChatPhotoClass = &ChatPhoto{}
)

func ( *ChatPhoto) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.HasVideo == 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 ( *ChatPhoto) () string {
	if  == nil {
		return "ChatPhoto(nil)"
	}
	type  ChatPhoto
	return fmt.Sprintf("ChatPhoto%+v", (*))
}

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

	.DCID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *ChatPhoto) () tdp.Type {
	 := tdp.Type{
		Name: "chatPhoto",
		ID:   ChatPhotoTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "HasVideo",
			SchemaName: "has_video",
			Null:       !.Flags.Has(0),
		},
		{
			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 ( *ChatPhoto) () {
	if !(.HasVideo == false) {
		.Flags.Set(0)
	}
	if !(.StrippedThumb == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *ChatPhoto) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatPhoto#1c6e1c11 as nil")
	}
	.PutID(ChatPhotoTypeID)
	return .EncodeBare()
}

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

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

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

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

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

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

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

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

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

// ChatPhotoClassName is schema name of ChatPhotoClass.
const ChatPhotoClassName = "ChatPhoto"

// ChatPhotoClass represents ChatPhoto generic type.
//
// See https://core.telegram.org/type/ChatPhoto for reference.
//
// Example:
//
//	g, err := tg.DecodeChatPhoto(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.ChatPhotoEmpty: // chatPhotoEmpty#37c1011c
//	case *tg.ChatPhoto: // chatPhoto#1c6e1c11
//	default: panic(v)
//	}
type ChatPhotoClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ChatPhotoClass

	// 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 ChatPhotoClass to ChatPhoto.
	AsNotEmpty() (*ChatPhoto, bool)
}

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

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

// DecodeChatPhoto implements binary de-serialization for ChatPhotoClass.
func ( *bin.Buffer) (ChatPhotoClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case ChatPhotoEmptyTypeID:
		// Decoding chatPhotoEmpty#37c1011c.
		 := ChatPhotoEmpty{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ChatPhotoClass: %w", )
		}
		return &, nil
	case ChatPhotoTypeID:
		// Decoding chatPhoto#1c6e1c11.
		 := ChatPhoto{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ChatPhotoClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode ChatPhotoClass: %w", bin.NewUnexpectedID())
	}
}

// ChatPhoto boxes the ChatPhotoClass providing a helper.
type ChatPhotoBox struct {
	ChatPhoto ChatPhotoClass
}

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

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