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

// MessageFwdHeader represents TL type `messageFwdHeader#5f777dce`.
// Info about a forwarded message
//
// See https://core.telegram.org/constructor/messageFwdHeader for reference.
type MessageFwdHeader struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this message was imported from a foreign chat service, click here for more
	// info »¹
	//
	// Links:
	//  1) https://core.telegram.org/api/import
	Imported bool
	// The ID of the user that originally sent the message
	//
	// Use SetFromID and GetFromID helpers.
	FromID PeerClass
	// The name of the user that originally sent the message
	//
	// Use SetFromName and GetFromName helpers.
	FromName string
	// When was the message originally sent
	Date int
	// ID of the channel message that was forwarded
	//
	// Use SetChannelPost and GetChannelPost helpers.
	ChannelPost int
	// For channels and if signatures are enabled, author of the channel message
	//
	// Use SetPostAuthor and GetPostAuthor helpers.
	PostAuthor string
	// Only for messages forwarded to the current user (inputPeerSelf), full info about the
	// user/channel that originally sent the message
	//
	// Use SetSavedFromPeer and GetSavedFromPeer helpers.
	SavedFromPeer PeerClass
	// Only for messages forwarded to the current user (inputPeerSelf), ID of the message
	// that was forwarded from the original user/channel
	//
	// Use SetSavedFromMsgID and GetSavedFromMsgID helpers.
	SavedFromMsgID int
	// PSA type
	//
	// Use SetPsaType and GetPsaType helpers.
	PsaType string
}

// MessageFwdHeaderTypeID is TL type id of MessageFwdHeader.
const MessageFwdHeaderTypeID = 0x5f777dce

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

func ( *MessageFwdHeader) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Imported == false) {
		return false
	}
	if !(.FromID == nil) {
		return false
	}
	if !(.FromName == "") {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.ChannelPost == 0) {
		return false
	}
	if !(.PostAuthor == "") {
		return false
	}
	if !(.SavedFromPeer == nil) {
		return false
	}
	if !(.SavedFromMsgID == 0) {
		return false
	}
	if !(.PsaType == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessageFwdHeader from given interface.
func ( *MessageFwdHeader) ( interface {
	() ( bool)
	() ( PeerClass,  bool)
	() ( string,  bool)
	() ( int)
	() ( int,  bool)
	() ( string,  bool)
	() ( PeerClass,  bool)
	() ( int,  bool)
	() ( string,  bool)
}) {
	.Imported = .()
	if ,  := .();  {
		.FromID = 
	}

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

	.Date = .()
	if ,  := .();  {
		.ChannelPost = 
	}

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

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *MessageFwdHeader) () tdp.Type {
	 := tdp.Type{
		Name: "messageFwdHeader",
		ID:   MessageFwdHeaderTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Imported",
			SchemaName: "imported",
			Null:       !.Flags.Has(7),
		},
		{
			Name:       "FromID",
			SchemaName: "from_id",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "FromName",
			SchemaName: "from_name",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "ChannelPost",
			SchemaName: "channel_post",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "PostAuthor",
			SchemaName: "post_author",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "SavedFromPeer",
			SchemaName: "saved_from_peer",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "SavedFromMsgID",
			SchemaName: "saved_from_msg_id",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "PsaType",
			SchemaName: "psa_type",
			Null:       !.Flags.Has(6),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessageFwdHeader) () {
	if !(.Imported == false) {
		.Flags.Set(7)
	}
	if !(.FromID == nil) {
		.Flags.Set(0)
	}
	if !(.FromName == "") {
		.Flags.Set(5)
	}
	if !(.ChannelPost == 0) {
		.Flags.Set(2)
	}
	if !(.PostAuthor == "") {
		.Flags.Set(3)
	}
	if !(.SavedFromPeer == nil) {
		.Flags.Set(4)
	}
	if !(.SavedFromMsgID == 0) {
		.Flags.Set(4)
	}
	if !(.PsaType == "") {
		.Flags.Set(6)
	}
}

// Encode implements bin.Encoder.
func ( *MessageFwdHeader) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageFwdHeader#5f777dce as nil")
	}
	.PutID(MessageFwdHeaderTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessageFwdHeader) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messageFwdHeader#5f777dce as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messageFwdHeader#5f777dce: field flags: %w", )
	}
	if .Flags.Has(0) {
		if .FromID == nil {
			return fmt.Errorf("unable to encode messageFwdHeader#5f777dce: field from_id is nil")
		}
		if  := .FromID.Encode();  != nil {
			return fmt.Errorf("unable to encode messageFwdHeader#5f777dce: field from_id: %w", )
		}
	}
	if .Flags.Has(5) {
		.PutString(.FromName)
	}
	.PutInt(.Date)
	if .Flags.Has(2) {
		.PutInt(.ChannelPost)
	}
	if .Flags.Has(3) {
		.PutString(.PostAuthor)
	}
	if .Flags.Has(4) {
		if .SavedFromPeer == nil {
			return fmt.Errorf("unable to encode messageFwdHeader#5f777dce: field saved_from_peer is nil")
		}
		if  := .SavedFromPeer.Encode();  != nil {
			return fmt.Errorf("unable to encode messageFwdHeader#5f777dce: field saved_from_peer: %w", )
		}
	}
	if .Flags.Has(4) {
		.PutInt(.SavedFromMsgID)
	}
	if .Flags.Has(6) {
		.PutString(.PsaType)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessageFwdHeader) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messageFwdHeader#5f777dce to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field flags: %w", )
		}
	}
	.Imported = .Flags.Has(7)
	if .Flags.Has(0) {
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field from_id: %w", )
		}
		.FromID = 
	}
	if .Flags.Has(5) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field from_name: %w", )
		}
		.FromName = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field date: %w", )
		}
		.Date = 
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field channel_post: %w", )
		}
		.ChannelPost = 
	}
	if .Flags.Has(3) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field post_author: %w", )
		}
		.PostAuthor = 
	}
	if .Flags.Has(4) {
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field saved_from_peer: %w", )
		}
		.SavedFromPeer = 
	}
	if .Flags.Has(4) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field saved_from_msg_id: %w", )
		}
		.SavedFromMsgID = 
	}
	if .Flags.Has(6) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field psa_type: %w", )
		}
		.PsaType = 
	}
	return nil
}

// SetImported sets value of Imported conditional field.
func ( *MessageFwdHeader) ( bool) {
	if  {
		.Flags.Set(7)
		.Imported = true
	} else {
		.Flags.Unset(7)
		.Imported = false
	}
}

// GetImported returns value of Imported conditional field.
func ( *MessageFwdHeader) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(7)
}

// SetFromID sets value of FromID conditional field.
func ( *MessageFwdHeader) ( PeerClass) {
	.Flags.Set(0)
	.FromID = 
}

// GetFromID returns value of FromID conditional field and
// boolean which is true if field was set.
func ( *MessageFwdHeader) () ( PeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .FromID, true
}

// SetFromName sets value of FromName conditional field.
func ( *MessageFwdHeader) ( string) {
	.Flags.Set(5)
	.FromName = 
}

// GetFromName returns value of FromName conditional field and
// boolean which is true if field was set.
func ( *MessageFwdHeader) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(5) {
		return , false
	}
	return .FromName, true
}

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

// SetChannelPost sets value of ChannelPost conditional field.
func ( *MessageFwdHeader) ( int) {
	.Flags.Set(2)
	.ChannelPost = 
}

// GetChannelPost returns value of ChannelPost conditional field and
// boolean which is true if field was set.
func ( *MessageFwdHeader) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .ChannelPost, true
}

// SetPostAuthor sets value of PostAuthor conditional field.
func ( *MessageFwdHeader) ( string) {
	.Flags.Set(3)
	.PostAuthor = 
}

// GetPostAuthor returns value of PostAuthor conditional field and
// boolean which is true if field was set.
func ( *MessageFwdHeader) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .PostAuthor, true
}

// SetSavedFromPeer sets value of SavedFromPeer conditional field.
func ( *MessageFwdHeader) ( PeerClass) {
	.Flags.Set(4)
	.SavedFromPeer = 
}

// GetSavedFromPeer returns value of SavedFromPeer conditional field and
// boolean which is true if field was set.
func ( *MessageFwdHeader) () ( PeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .SavedFromPeer, true
}

// SetSavedFromMsgID sets value of SavedFromMsgID conditional field.
func ( *MessageFwdHeader) ( int) {
	.Flags.Set(4)
	.SavedFromMsgID = 
}

// GetSavedFromMsgID returns value of SavedFromMsgID conditional field and
// boolean which is true if field was set.
func ( *MessageFwdHeader) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .SavedFromMsgID, true
}

// SetPsaType sets value of PsaType conditional field.
func ( *MessageFwdHeader) ( string) {
	.Flags.Set(6)
	.PsaType = 
}

// GetPsaType returns value of PsaType conditional field and
// boolean which is true if field was set.
func ( *MessageFwdHeader) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(6) {
		return , false
	}
	return .PsaType, true
}