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

// StoriesSendStoryRequest represents TL type `stories.sendStory#e4e6694b`.
// Uploads a Telegram Story¹.
//
// Links:
//  1. https://core.telegram.org/api/stories
//
// See https://core.telegram.org/method/stories.sendStory for reference.
type StoriesSendStoryRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether to add the story to the profile automatically upon expiration. If not set, the
	// story will only be added to the archive, see here »¹ for more info.
	//
	// Links:
	//  1) https://core.telegram.org/api/stories
	Pinned bool
	// If set, disables forwards, screenshots, and downloads.
	Noforwards bool
	// Set this flag when reposting stories with fwd_from_id+fwd_from_id, if the media was
	// modified before reposting.
	FwdModified bool
	// The peer to send the story as.
	Peer InputPeerClass
	// The story media.
	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
	// Story caption.
	//
	// Use SetCaption and GetCaption helpers.
	Caption string
	// Message entities for styled text¹, 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
	// Privacy rules¹ for the story, indicating who can or can't view the story.
	//
	// Links:
	//  1) https://core.telegram.org/api/privacy
	PrivacyRules []InputPrivacyRuleClass
	// Unique client message ID required to prevent message resending.
	RandomID int64
	// Period after which the story is moved to archive (and to the profile if pinned is set)
	// in seconds; must be one of 6 * 3600, 12 * 3600, 86400, or 2 * 86400 for Telegram
	// Premium users, and 86400 otherwise.
	//
	// Use SetPeriod and GetPeriod helpers.
	Period int
	// If set, indicates that this story is a repost of story with ID fwd_from_story posted
	// by the peer in fwd_from_id.
	//
	// Use SetFwdFromID and GetFwdFromID helpers.
	FwdFromID InputPeerClass
	// If set, indicates that this story is a repost of story with ID fwd_from_story posted
	// by the peer in fwd_from_id.
	//
	// Use SetFwdFromStory and GetFwdFromStory helpers.
	FwdFromStory int
}

// StoriesSendStoryRequestTypeID is TL type id of StoriesSendStoryRequest.
const StoriesSendStoryRequestTypeID = 0xe4e6694b

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

func ( *StoriesSendStoryRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Pinned == false) {
		return false
	}
	if !(.Noforwards == false) {
		return false
	}
	if !(.FwdModified == false) {
		return false
	}
	if !(.Peer == nil) {
		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
	}
	if !(.RandomID == 0) {
		return false
	}
	if !(.Period == 0) {
		return false
	}
	if !(.FwdFromID == nil) {
		return false
	}
	if !(.FwdFromStory == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StoriesSendStoryRequest from given interface.
func ( *StoriesSendStoryRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( InputPeerClass)
	() ( InputMediaClass)
	() ( []MediaAreaClass,  bool)
	() ( string,  bool)
	() ( []MessageEntityClass,  bool)
	() ( []InputPrivacyRuleClass)
	() ( int64)
	() ( int,  bool)
	() ( InputPeerClass,  bool)
	() ( int,  bool)
}) {
	.Pinned = .()
	.Noforwards = .()
	.FwdModified = .()
	.Peer = .()
	.Media = .()
	if ,  := .();  {
		.MediaAreas = 
	}

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

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

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *StoriesSendStoryRequest) () tdp.Type {
	 := tdp.Type{
		Name: "stories.sendStory",
		ID:   StoriesSendStoryRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Pinned",
			SchemaName: "pinned",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Noforwards",
			SchemaName: "noforwards",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "FwdModified",
			SchemaName: "fwd_modified",
			Null:       !.Flags.Has(7),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Media",
			SchemaName: "media",
		},
		{
			Name:       "MediaAreas",
			SchemaName: "media_areas",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "Caption",
			SchemaName: "caption",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "PrivacyRules",
			SchemaName: "privacy_rules",
		},
		{
			Name:       "RandomID",
			SchemaName: "random_id",
		},
		{
			Name:       "Period",
			SchemaName: "period",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "FwdFromID",
			SchemaName: "fwd_from_id",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "FwdFromStory",
			SchemaName: "fwd_from_story",
			Null:       !.Flags.Has(6),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StoriesSendStoryRequest) () {
	if !(.Pinned == false) {
		.Flags.Set(2)
	}
	if !(.Noforwards == false) {
		.Flags.Set(4)
	}
	if !(.FwdModified == false) {
		.Flags.Set(7)
	}
	if !(.MediaAreas == nil) {
		.Flags.Set(5)
	}
	if !(.Caption == "") {
		.Flags.Set(0)
	}
	if !(.Entities == nil) {
		.Flags.Set(1)
	}
	if !(.Period == 0) {
		.Flags.Set(3)
	}
	if !(.FwdFromID == nil) {
		.Flags.Set(6)
	}
	if !(.FwdFromStory == 0) {
		.Flags.Set(6)
	}
}

// Encode implements bin.Encoder.
func ( *StoriesSendStoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode stories.sendStory#e4e6694b as nil")
	}
	.PutID(StoriesSendStoryRequestTypeID)
	return .EncodeBare()
}

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

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

// DecodeBare implements bin.BareDecoder.
func ( *StoriesSendStoryRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode stories.sendStory#e4e6694b to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode stories.sendStory#e4e6694b: field flags: %w", )
		}
	}
	.Pinned = .Flags.Has(2)
	.Noforwards = .Flags.Has(4)
	.FwdModified = .Flags.Has(7)
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode stories.sendStory#e4e6694b: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := DecodeInputMedia()
		if  != nil {
			return fmt.Errorf("unable to decode stories.sendStory#e4e6694b: field media: %w", )
		}
		.Media = 
	}
	if .Flags.Has(5) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode stories.sendStory#e4e6694b: field media_areas: %w", )
		}

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

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

		if  > 0 {
			.PrivacyRules = make([]InputPrivacyRuleClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeInputPrivacyRule()
			if  != nil {
				return fmt.Errorf("unable to decode stories.sendStory#e4e6694b: field privacy_rules: %w", )
			}
			.PrivacyRules = append(.PrivacyRules, )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode stories.sendStory#e4e6694b: field random_id: %w", )
		}
		.RandomID = 
	}
	if .Flags.Has(3) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode stories.sendStory#e4e6694b: field period: %w", )
		}
		.Period = 
	}
	if .Flags.Has(6) {
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode stories.sendStory#e4e6694b: field fwd_from_id: %w", )
		}
		.FwdFromID = 
	}
	if .Flags.Has(6) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode stories.sendStory#e4e6694b: field fwd_from_story: %w", )
		}
		.FwdFromStory = 
	}
	return nil
}

// SetPinned sets value of Pinned conditional field.
func ( *StoriesSendStoryRequest) ( bool) {
	if  {
		.Flags.Set(2)
		.Pinned = true
	} else {
		.Flags.Unset(2)
		.Pinned = false
	}
}

// GetPinned returns value of Pinned conditional field.
func ( *StoriesSendStoryRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetNoforwards sets value of Noforwards conditional field.
func ( *StoriesSendStoryRequest) ( bool) {
	if  {
		.Flags.Set(4)
		.Noforwards = true
	} else {
		.Flags.Unset(4)
		.Noforwards = false
	}
}

// GetNoforwards returns value of Noforwards conditional field.
func ( *StoriesSendStoryRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(4)
}

// SetFwdModified sets value of FwdModified conditional field.
func ( *StoriesSendStoryRequest) ( bool) {
	if  {
		.Flags.Set(7)
		.FwdModified = true
	} else {
		.Flags.Unset(7)
		.FwdModified = false
	}
}

// GetFwdModified returns value of FwdModified conditional field.
func ( *StoriesSendStoryRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(7)
}

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

// GetMedia returns value of Media field.
func ( *StoriesSendStoryRequest) () ( InputMediaClass) {
	if  == nil {
		return
	}
	return .Media
}

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

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

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

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

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

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

// GetPrivacyRules returns value of PrivacyRules field.
func ( *StoriesSendStoryRequest) () ( []InputPrivacyRuleClass) {
	if  == nil {
		return
	}
	return .PrivacyRules
}

// GetRandomID returns value of RandomID field.
func ( *StoriesSendStoryRequest) () ( int64) {
	if  == nil {
		return
	}
	return .RandomID
}

// SetPeriod sets value of Period conditional field.
func ( *StoriesSendStoryRequest) ( int) {
	.Flags.Set(3)
	.Period = 
}

// GetPeriod returns value of Period conditional field and
// boolean which is true if field was set.
func ( *StoriesSendStoryRequest) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Period, true
}

// SetFwdFromID sets value of FwdFromID conditional field.
func ( *StoriesSendStoryRequest) ( InputPeerClass) {
	.Flags.Set(6)
	.FwdFromID = 
}

// GetFwdFromID returns value of FwdFromID conditional field and
// boolean which is true if field was set.
func ( *StoriesSendStoryRequest) () ( InputPeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(6) {
		return , false
	}
	return .FwdFromID, true
}

// SetFwdFromStory sets value of FwdFromStory conditional field.
func ( *StoriesSendStoryRequest) ( int) {
	.Flags.Set(6)
	.FwdFromStory = 
}

// GetFwdFromStory returns value of FwdFromStory conditional field and
// boolean which is true if field was set.
func ( *StoriesSendStoryRequest) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(6) {
		return , false
	}
	return .FwdFromStory, true
}

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

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

// MapPrivacyRules returns field PrivacyRules wrapped in InputPrivacyRuleClassArray helper.
func ( *StoriesSendStoryRequest) () ( InputPrivacyRuleClassArray) {
	return InputPrivacyRuleClassArray(.PrivacyRules)
}

// StoriesSendStory invokes method stories.sendStory#e4e6694b returning error if any.
// Uploads a Telegram Story¹.
//
// Links:
//  1. https://core.telegram.org/api/stories
//
// Possible errors:
//
//	400 IMAGE_PROCESS_FAILED: Failure while processing image.
//	400 MEDIA_EMPTY: The provided media object is invalid.
//	400 MEDIA_FILE_INVALID: The specified media file is invalid.
//	400 MEDIA_TYPE_INVALID: The specified media type cannot be used in stories.
//	400 MEDIA_VIDEO_STORY_MISSING:
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//	400 PREMIUM_ACCOUNT_REQUIRED: A premium account is required to execute this action.
//	400 STORIES_TOO_MUCH: You have hit the maximum active stories limit as specified by the story_expiring_limit_* client configuration parameters: you should buy a Premium subscription, delete an active story, or wait for the oldest story to expire.
//	400 STORY_PERIOD_INVALID: The specified story period is invalid for this account.
//	400 VENUE_ID_INVALID: The specified venue ID is invalid.
//
// See https://core.telegram.org/method/stories.sendStory for reference.
func ( *Client) ( context.Context,  *StoriesSendStoryRequest) (UpdatesClass, error) {
	var  UpdatesBox

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