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

// StoryFwdHeader represents TL type `storyFwdHeader#b826e150`.
// Contains info about the original poster of a reposted story.
//
// See https://core.telegram.org/constructor/storyFwdHeader for reference.
type StoryFwdHeader struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether the story media was modified before reposting it (for example by overlaying a
	// round video with a reaction).
	Modified bool
	// Peer that originally posted the story; will be empty for stories forwarded from a user
	// with forwards privacy enabled, in which case from_name will be set, instead.
	//
	// Use SetFrom and GetFrom helpers.
	From PeerClass
	// Will be set for stories forwarded from a user with forwards privacy enabled, in which
	// case from will also be empty.
	//
	// Use SetFromName and GetFromName helpers.
	FromName string
	// , contains the story ID
	//
	// Use SetStoryID and GetStoryID helpers.
	StoryID int
}

// StoryFwdHeaderTypeID is TL type id of StoryFwdHeader.
const StoryFwdHeaderTypeID = 0xb826e150

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

func ( *StoryFwdHeader) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Modified == false) {
		return false
	}
	if !(.From == nil) {
		return false
	}
	if !(.FromName == "") {
		return false
	}
	if !(.StoryID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StoryFwdHeader from given interface.
func ( *StoryFwdHeader) ( interface {
	() ( bool)
	() ( PeerClass,  bool)
	() ( string,  bool)
	() ( int,  bool)
}) {
	.Modified = .()
	if ,  := .();  {
		.From = 
	}

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *StoryFwdHeader) () tdp.Type {
	 := tdp.Type{
		Name: "storyFwdHeader",
		ID:   StoryFwdHeaderTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Modified",
			SchemaName: "modified",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "From",
			SchemaName: "from",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "FromName",
			SchemaName: "from_name",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "StoryID",
			SchemaName: "story_id",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StoryFwdHeader) () {
	if !(.Modified == false) {
		.Flags.Set(3)
	}
	if !(.From == nil) {
		.Flags.Set(0)
	}
	if !(.FromName == "") {
		.Flags.Set(1)
	}
	if !(.StoryID == 0) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *StoryFwdHeader) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode storyFwdHeader#b826e150 as nil")
	}
	.PutID(StoryFwdHeaderTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StoryFwdHeader) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode storyFwdHeader#b826e150 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode storyFwdHeader#b826e150: field flags: %w", )
	}
	if .Flags.Has(0) {
		if .From == nil {
			return fmt.Errorf("unable to encode storyFwdHeader#b826e150: field from is nil")
		}
		if  := .From.Encode();  != nil {
			return fmt.Errorf("unable to encode storyFwdHeader#b826e150: field from: %w", )
		}
	}
	if .Flags.Has(1) {
		.PutString(.FromName)
	}
	if .Flags.Has(2) {
		.PutInt(.StoryID)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StoryFwdHeader) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode storyFwdHeader#b826e150 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode storyFwdHeader#b826e150: field flags: %w", )
		}
	}
	.Modified = .Flags.Has(3)
	if .Flags.Has(0) {
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode storyFwdHeader#b826e150: field from: %w", )
		}
		.From = 
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode storyFwdHeader#b826e150: field from_name: %w", )
		}
		.FromName = 
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode storyFwdHeader#b826e150: field story_id: %w", )
		}
		.StoryID = 
	}
	return nil
}

// SetModified sets value of Modified conditional field.
func ( *StoryFwdHeader) ( bool) {
	if  {
		.Flags.Set(3)
		.Modified = true
	} else {
		.Flags.Unset(3)
		.Modified = false
	}
}

// GetModified returns value of Modified conditional field.
func ( *StoryFwdHeader) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(3)
}

// SetFrom sets value of From conditional field.
func ( *StoryFwdHeader) ( PeerClass) {
	.Flags.Set(0)
	.From = 
}

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

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

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

// SetStoryID sets value of StoryID conditional field.
func ( *StoryFwdHeader) ( int) {
	.Flags.Set(2)
	.StoryID = 
}

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