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

// MessageViews represents TL type `messageViews#455b853d`.
// View, forward counter + info about replies of a specific message
//
// See https://core.telegram.org/constructor/messageViews for reference.
type MessageViews struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// View count of message
	//
	// Use SetViews and GetViews helpers.
	Views int
	// Forward count of message
	//
	// Use SetForwards and GetForwards helpers.
	Forwards int
	// Reply and thread¹ information of message
	//
	// Links:
	//  1) https://core.telegram.org/api/threads
	//
	// Use SetReplies and GetReplies helpers.
	Replies MessageReplies
}

// MessageViewsTypeID is TL type id of MessageViews.
const MessageViewsTypeID = 0x455b853d

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

func ( *MessageViews) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Views == 0) {
		return false
	}
	if !(.Forwards == 0) {
		return false
	}
	if !(.Replies.Zero()) {
		return false
	}

	return true
}

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

// FillFrom fills MessageViews from given interface.
func ( *MessageViews) ( interface {
	() ( int,  bool)
	() ( int,  bool)
	() ( MessageReplies,  bool)
}) {
	if ,  := .();  {
		.Views = 
	}

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *MessageViews) () tdp.Type {
	 := tdp.Type{
		Name: "messageViews",
		ID:   MessageViewsTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Views",
			SchemaName: "views",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Forwards",
			SchemaName: "forwards",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Replies",
			SchemaName: "replies",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessageViews) () {
	if !(.Views == 0) {
		.Flags.Set(0)
	}
	if !(.Forwards == 0) {
		.Flags.Set(1)
	}
	if !(.Replies.Zero()) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *MessageViews) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageViews#455b853d as nil")
	}
	.PutID(MessageViewsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessageViews) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageViews#455b853d as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messageViews#455b853d: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutInt(.Views)
	}
	if .Flags.Has(1) {
		.PutInt(.Forwards)
	}
	if .Flags.Has(2) {
		if  := .Replies.Encode();  != nil {
			return fmt.Errorf("unable to encode messageViews#455b853d: field replies: %w", )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessageViews) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messageViews#455b853d to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messageViews#455b853d: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageViews#455b853d: field views: %w", )
		}
		.Views = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageViews#455b853d: field forwards: %w", )
		}
		.Forwards = 
	}
	if .Flags.Has(2) {
		if  := .Replies.Decode();  != nil {
			return fmt.Errorf("unable to decode messageViews#455b853d: field replies: %w", )
		}
	}
	return nil
}

// SetViews sets value of Views conditional field.
func ( *MessageViews) ( int) {
	.Flags.Set(0)
	.Views = 
}

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

// SetForwards sets value of Forwards conditional field.
func ( *MessageViews) ( int) {
	.Flags.Set(1)
	.Forwards = 
}

// GetForwards returns value of Forwards conditional field and
// boolean which is true if field was set.
func ( *MessageViews) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Forwards, true
}

// SetReplies sets value of Replies conditional field.
func ( *MessageViews) ( MessageReplies) {
	.Flags.Set(2)
	.Replies = 
}

// GetReplies returns value of Replies conditional field and
// boolean which is true if field was set.
func ( *MessageViews) () ( MessageReplies,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .Replies, true
}