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

// StoriesEditStoryRequest represents TL type `stories.editStory#b583ba46`.
// Edit an uploaded story¹
//
// Links:
//  1. https://core.telegram.org/api/stories
//
// See https://core.telegram.org/method/stories.editStory for reference.
type StoriesEditStoryRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Peer where the story was posted.
	Peer InputPeerClass
	// ID of story to edit.
	ID int
	// If specified, replaces the story media.
	//
	// Use SetMedia and GetMedia helpers.
	Media InputMediaClass
	// Media areas¹ associated to the story, see here »² for more info.
	//
	// Links:
	//  1) https://core.telegram.org/api/stories#media-areas
	//  2) https://core.telegram.org/api/stories#media-areas
	//
	// Use SetMediaAreas and GetMediaAreas helpers.
	MediaAreas []MediaAreaClass
	// If specified, replaces the story caption.
	//
	// Use SetCaption and GetCaption helpers.
	Caption string
	// Message entities for styled text in the caption¹, if allowed by the stories_entities
	// client configuration parameter »².
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	//  2) https://core.telegram.org/api/config#stories-entities
	//
	// Use SetEntities and GetEntities helpers.
	Entities []MessageEntityClass
	// If specified, alters the privacy settings »¹ of the story, changing who can or can't
	// view the story.
	//
	// Links:
	//  1) https://core.telegram.org/api/privacy
	//
	// Use SetPrivacyRules and GetPrivacyRules helpers.
	PrivacyRules []InputPrivacyRuleClass
}

// StoriesEditStoryRequestTypeID is TL type id of StoriesEditStoryRequest.
const StoriesEditStoryRequestTypeID = 0xb583ba46

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

func ( *StoriesEditStoryRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.Media == nil) {
		return false
	}
	if !(.MediaAreas == nil) {
		return false
	}
	if !(.Caption == "") {
		return false
	}
	if !(.Entities == nil) {
		return false
	}
	if !(.PrivacyRules == nil) {
		return false
	}

	return true
}

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

// FillFrom fills StoriesEditStoryRequest from given interface.
func ( *StoriesEditStoryRequest) ( interface {
	() ( InputPeerClass)
	() ( int)
	() ( InputMediaClass,  bool)
	() ( []MediaAreaClass,  bool)
	() ( string,  bool)
	() ( []MessageEntityClass,  bool)
	() ( []InputPrivacyRuleClass,  bool)
}) {
	.Peer = .()
	.ID = .()
	if ,  := .();  {
		.Media = 
	}

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

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

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

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

}

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

// TypeName returns name of type in TL schema.
func (*StoriesEditStoryRequest) () string {
	return "stories.editStory"
}

// TypeInfo returns info about TL type.
func ( *StoriesEditStoryRequest) () tdp.Type {
	 := tdp.Type{
		Name: "stories.editStory",
		ID:   StoriesEditStoryRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Media",
			SchemaName: "media",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "MediaAreas",
			SchemaName: "media_areas",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Caption",
			SchemaName: "caption",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "PrivacyRules",
			SchemaName: "privacy_rules",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StoriesEditStoryRequest) () {
	if !(.Media == nil) {
		.Flags.Set(0)
	}
	if !(.MediaAreas == nil) {
		.Flags.Set(3)
	}
	if !(.Caption == "") {
		.Flags.Set(1)
	}
	if !(.Entities == nil) {
		.Flags.Set(1)
	}
	if !(.PrivacyRules == nil) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *StoriesEditStoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.editStory#b583ba46 as nil")
	}
	.PutID(StoriesEditStoryRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StoriesEditStoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.editStory#b583ba46 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode stories.editStory#b583ba46: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode stories.editStory#b583ba46: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode stories.editStory#b583ba46: field peer: %w", )
	}
	.PutInt(.ID)
	if .Flags.Has(0) {
		if .Media == nil {
			return fmt.Errorf("unable to encode stories.editStory#b583ba46: field media is nil")
		}
		if  := .Media.Encode();  != nil {
			return fmt.Errorf("unable to encode stories.editStory#b583ba46: field media: %w", )
		}
	}
	if .Flags.Has(3) {
		.PutVectorHeader(len(.MediaAreas))
		for ,  := range .MediaAreas {
			if  == nil {
				return fmt.Errorf("unable to encode stories.editStory#b583ba46: field media_areas element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode stories.editStory#b583ba46: field media_areas element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(1) {
		.PutString(.Caption)
	}
	if .Flags.Has(1) {
		.PutVectorHeader(len(.Entities))
		for ,  := range .Entities {
			if  == nil {
				return fmt.Errorf("unable to encode stories.editStory#b583ba46: field entities element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode stories.editStory#b583ba46: field entities element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(2) {
		.PutVectorHeader(len(.PrivacyRules))
		for ,  := range .PrivacyRules {
			if  == nil {
				return fmt.Errorf("unable to encode stories.editStory#b583ba46: field privacy_rules element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode stories.editStory#b583ba46: field privacy_rules element with index %d: %w", , )
			}
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StoriesEditStoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode stories.editStory#b583ba46 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode stories.editStory#b583ba46: field flags: %w", )
		}
	}
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode stories.editStory#b583ba46: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode stories.editStory#b583ba46: field id: %w", )
		}
		.ID = 
	}
	if .Flags.Has(0) {
		,  := DecodeInputMedia()
		if  != nil {
			return fmt.Errorf("unable to decode stories.editStory#b583ba46: field media: %w", )
		}
		.Media = 
	}
	if .Flags.Has(3) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode stories.editStory#b583ba46: field media_areas: %w", )
		}

		if  > 0 {
			.MediaAreas = make([]MediaAreaClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMediaArea()
			if  != nil {
				return fmt.Errorf("unable to decode stories.editStory#b583ba46: field media_areas: %w", )
			}
			.MediaAreas = append(.MediaAreas, )
		}
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode stories.editStory#b583ba46: field caption: %w", )
		}
		.Caption = 
	}
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode stories.editStory#b583ba46: field entities: %w", )
		}

		if  > 0 {
			.Entities = make([]MessageEntityClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessageEntity()
			if  != nil {
				return fmt.Errorf("unable to decode stories.editStory#b583ba46: field entities: %w", )
			}
			.Entities = append(.Entities, )
		}
	}
	if .Flags.Has(2) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode stories.editStory#b583ba46: field privacy_rules: %w", )
		}

		if  > 0 {
			.PrivacyRules = make([]InputPrivacyRuleClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeInputPrivacyRule()
			if  != nil {
				return fmt.Errorf("unable to decode stories.editStory#b583ba46: field privacy_rules: %w", )
			}
			.PrivacyRules = append(.PrivacyRules, )
		}
	}
	return nil
}

// GetPeer returns value of Peer field.
func ( *StoriesEditStoryRequest) () ( InputPeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

// GetID returns value of ID field.
func ( *StoriesEditStoryRequest) () ( int) {
	if  == nil {
		return
	}
	return .ID
}

// SetMedia sets value of Media conditional field.
func ( *StoriesEditStoryRequest) ( InputMediaClass) {
	.Flags.Set(0)
	.Media = 
}

// GetMedia returns value of Media conditional field and
// boolean which is true if field was set.
func ( *StoriesEditStoryRequest) () ( InputMediaClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Media, true
}

// SetMediaAreas sets value of MediaAreas conditional field.
func ( *StoriesEditStoryRequest) ( []MediaAreaClass) {
	.Flags.Set(3)
	.MediaAreas = 
}

// GetMediaAreas returns value of MediaAreas conditional field and
// boolean which is true if field was set.
func ( *StoriesEditStoryRequest) () ( []MediaAreaClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .MediaAreas, true
}

// SetCaption sets value of Caption conditional field.
func ( *StoriesEditStoryRequest) ( string) {
	.Flags.Set(1)
	.Caption = 
}

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

// SetEntities sets value of Entities conditional field.
func ( *StoriesEditStoryRequest) ( []MessageEntityClass) {
	.Flags.Set(1)
	.Entities = 
}

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

// SetPrivacyRules sets value of PrivacyRules conditional field.
func ( *StoriesEditStoryRequest) ( []InputPrivacyRuleClass) {
	.Flags.Set(2)
	.PrivacyRules = 
}

// GetPrivacyRules returns value of PrivacyRules conditional field and
// boolean which is true if field was set.
func ( *StoriesEditStoryRequest) () ( []InputPrivacyRuleClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .PrivacyRules, true
}

// MapMediaAreas returns field MediaAreas wrapped in MediaAreaClassArray helper.
func ( *StoriesEditStoryRequest) () ( MediaAreaClassArray,  bool) {
	if !.Flags.Has(3) {
		return , false
	}
	return MediaAreaClassArray(.MediaAreas), true
}

// MapEntities returns field Entities wrapped in MessageEntityClassArray helper.
func ( *StoriesEditStoryRequest) () ( MessageEntityClassArray,  bool) {
	if !.Flags.Has(1) {
		return , false
	}
	return MessageEntityClassArray(.Entities), true
}

// MapPrivacyRules returns field PrivacyRules wrapped in InputPrivacyRuleClassArray helper.
func ( *StoriesEditStoryRequest) () ( InputPrivacyRuleClassArray,  bool) {
	if !.Flags.Has(2) {
		return , false
	}
	return InputPrivacyRuleClassArray(.PrivacyRules), true
}

// StoriesEditStory invokes method stories.editStory#b583ba46 returning error if any.
// Edit an uploaded story¹
//
// Links:
//  1. https://core.telegram.org/api/stories
//
// Possible errors:
//
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//	400 STORY_NOT_MODIFIED: The new story information you passed is equal to the previous story information, thus it wasn't modified.
//
// See https://core.telegram.org/method/stories.editStory for reference.
func ( *Client) ( context.Context,  *StoriesEditStoryRequest) (UpdatesClass, error) {
	var  UpdatesBox

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return .Updates, nil
}