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

// StarsSubscription represents TL type `starsSubscription#2e6eab1a`.
// Represents a Telegram Star subscription »¹.
//
// Links:
//  1. https://core.telegram.org/api/invites#paid-invite-links
//
// See https://core.telegram.org/constructor/starsSubscription for reference.
type StarsSubscription struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this subscription was cancelled.
	Canceled bool
	// Whether we left the associated private channel, but we can still rejoin it using
	// payments.fulfillStarsSubscription¹ because the current subscription period hasn't
	// expired yet.
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.fulfillStarsSubscription
	CanRefulfill bool
	// Whether this subscription has expired because there are not enough stars on the user's
	// balance to extend it.
	MissingBalance bool
	// Set if this bot subscription¹ was cancelled by the bot
	//
	// Links:
	//  1) https://core.telegram.org/api/subscriptions#bot-subscriptions
	BotCanceled bool
	// Subscription ID.
	ID string
	// Identifier of the associated private chat.
	Peer PeerClass
	// Expiration date of the current subscription period.
	UntilDate int
	// Pricing of the subscription in Telegram Stars.
	Pricing StarsSubscriptionPricing
	// Invitation link, used to renew the subscription after cancellation or expiration.
	//
	// Use SetChatInviteHash and GetChatInviteHash helpers.
	ChatInviteHash string
	// For bot subscriptions, the title of the subscription invoice
	//
	// Use SetTitle and GetTitle helpers.
	Title string
	// For bot subscriptions, the photo from the subscription invoice
	//
	// Use SetPhoto and GetPhoto helpers.
	Photo WebDocumentClass
	// For bot subscriptions, the identifier¹ of the subscription invoice
	//
	// Links:
	//  1) https://core.telegram.org/api/links#invoice-links
	//
	// Use SetInvoiceSlug and GetInvoiceSlug helpers.
	InvoiceSlug string
}

// StarsSubscriptionTypeID is TL type id of StarsSubscription.
const StarsSubscriptionTypeID = 0x2e6eab1a

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

func ( *StarsSubscription) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Canceled == false) {
		return false
	}
	if !(.CanRefulfill == false) {
		return false
	}
	if !(.MissingBalance == false) {
		return false
	}
	if !(.BotCanceled == false) {
		return false
	}
	if !(.ID == "") {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.UntilDate == 0) {
		return false
	}
	if !(.Pricing.Zero()) {
		return false
	}
	if !(.ChatInviteHash == "") {
		return false
	}
	if !(.Title == "") {
		return false
	}
	if !(.Photo == nil) {
		return false
	}
	if !(.InvoiceSlug == "") {
		return false
	}

	return true
}

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

// FillFrom fills StarsSubscription from given interface.
func ( *StarsSubscription) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( bool)
	() ( string)
	() ( PeerClass)
	() ( int)
	() ( StarsSubscriptionPricing)
	() ( string,  bool)
	() ( string,  bool)
	() ( WebDocumentClass,  bool)
	() ( string,  bool)
}) {
	.Canceled = .()
	.CanRefulfill = .()
	.MissingBalance = .()
	.BotCanceled = .()
	.ID = .()
	.Peer = .()
	.UntilDate = .()
	.Pricing = .()
	if ,  := .();  {
		.ChatInviteHash = 
	}

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *StarsSubscription) () tdp.Type {
	 := tdp.Type{
		Name: "starsSubscription",
		ID:   StarsSubscriptionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Canceled",
			SchemaName: "canceled",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "CanRefulfill",
			SchemaName: "can_refulfill",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "MissingBalance",
			SchemaName: "missing_balance",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "BotCanceled",
			SchemaName: "bot_canceled",
			Null:       !.Flags.Has(7),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "UntilDate",
			SchemaName: "until_date",
		},
		{
			Name:       "Pricing",
			SchemaName: "pricing",
		},
		{
			Name:       "ChatInviteHash",
			SchemaName: "chat_invite_hash",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Title",
			SchemaName: "title",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "Photo",
			SchemaName: "photo",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "InvoiceSlug",
			SchemaName: "invoice_slug",
			Null:       !.Flags.Has(6),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StarsSubscription) () {
	if !(.Canceled == false) {
		.Flags.Set(0)
	}
	if !(.CanRefulfill == false) {
		.Flags.Set(1)
	}
	if !(.MissingBalance == false) {
		.Flags.Set(2)
	}
	if !(.BotCanceled == false) {
		.Flags.Set(7)
	}
	if !(.ChatInviteHash == "") {
		.Flags.Set(3)
	}
	if !(.Title == "") {
		.Flags.Set(4)
	}
	if !(.Photo == nil) {
		.Flags.Set(5)
	}
	if !(.InvoiceSlug == "") {
		.Flags.Set(6)
	}
}

// Encode implements bin.Encoder.
func ( *StarsSubscription) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsSubscription#2e6eab1a as nil")
	}
	.PutID(StarsSubscriptionTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarsSubscription) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starsSubscription#2e6eab1a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode starsSubscription#2e6eab1a: field flags: %w", )
	}
	.PutString(.ID)
	if .Peer == nil {
		return fmt.Errorf("unable to encode starsSubscription#2e6eab1a: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode starsSubscription#2e6eab1a: field peer: %w", )
	}
	.PutInt(.UntilDate)
	if  := .Pricing.Encode();  != nil {
		return fmt.Errorf("unable to encode starsSubscription#2e6eab1a: field pricing: %w", )
	}
	if .Flags.Has(3) {
		.PutString(.ChatInviteHash)
	}
	if .Flags.Has(4) {
		.PutString(.Title)
	}
	if .Flags.Has(5) {
		if .Photo == nil {
			return fmt.Errorf("unable to encode starsSubscription#2e6eab1a: field photo is nil")
		}
		if  := .Photo.Encode();  != nil {
			return fmt.Errorf("unable to encode starsSubscription#2e6eab1a: field photo: %w", )
		}
	}
	if .Flags.Has(6) {
		.PutString(.InvoiceSlug)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StarsSubscription) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starsSubscription#2e6eab1a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode starsSubscription#2e6eab1a: field flags: %w", )
		}
	}
	.Canceled = .Flags.Has(0)
	.CanRefulfill = .Flags.Has(1)
	.MissingBalance = .Flags.Has(2)
	.BotCanceled = .Flags.Has(7)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode starsSubscription#2e6eab1a: field id: %w", )
		}
		.ID = 
	}
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode starsSubscription#2e6eab1a: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starsSubscription#2e6eab1a: field until_date: %w", )
		}
		.UntilDate = 
	}
	{
		if  := .Pricing.Decode();  != nil {
			return fmt.Errorf("unable to decode starsSubscription#2e6eab1a: field pricing: %w", )
		}
	}
	if .Flags.Has(3) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode starsSubscription#2e6eab1a: field chat_invite_hash: %w", )
		}
		.ChatInviteHash = 
	}
	if .Flags.Has(4) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode starsSubscription#2e6eab1a: field title: %w", )
		}
		.Title = 
	}
	if .Flags.Has(5) {
		,  := DecodeWebDocument()
		if  != nil {
			return fmt.Errorf("unable to decode starsSubscription#2e6eab1a: field photo: %w", )
		}
		.Photo = 
	}
	if .Flags.Has(6) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode starsSubscription#2e6eab1a: field invoice_slug: %w", )
		}
		.InvoiceSlug = 
	}
	return nil
}

// SetCanceled sets value of Canceled conditional field.
func ( *StarsSubscription) ( bool) {
	if  {
		.Flags.Set(0)
		.Canceled = true
	} else {
		.Flags.Unset(0)
		.Canceled = false
	}
}

// GetCanceled returns value of Canceled conditional field.
func ( *StarsSubscription) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetCanRefulfill sets value of CanRefulfill conditional field.
func ( *StarsSubscription) ( bool) {
	if  {
		.Flags.Set(1)
		.CanRefulfill = true
	} else {
		.Flags.Unset(1)
		.CanRefulfill = false
	}
}

// GetCanRefulfill returns value of CanRefulfill conditional field.
func ( *StarsSubscription) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetMissingBalance sets value of MissingBalance conditional field.
func ( *StarsSubscription) ( bool) {
	if  {
		.Flags.Set(2)
		.MissingBalance = true
	} else {
		.Flags.Unset(2)
		.MissingBalance = false
	}
}

// GetMissingBalance returns value of MissingBalance conditional field.
func ( *StarsSubscription) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

// SetBotCanceled sets value of BotCanceled conditional field.
func ( *StarsSubscription) ( bool) {
	if  {
		.Flags.Set(7)
		.BotCanceled = true
	} else {
		.Flags.Unset(7)
		.BotCanceled = false
	}
}

// GetBotCanceled returns value of BotCanceled conditional field.
func ( *StarsSubscription) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(7)
}

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

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

// GetUntilDate returns value of UntilDate field.
func ( *StarsSubscription) () ( int) {
	if  == nil {
		return
	}
	return .UntilDate
}

// GetPricing returns value of Pricing field.
func ( *StarsSubscription) () ( StarsSubscriptionPricing) {
	if  == nil {
		return
	}
	return .Pricing
}

// SetChatInviteHash sets value of ChatInviteHash conditional field.
func ( *StarsSubscription) ( string) {
	.Flags.Set(3)
	.ChatInviteHash = 
}

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

// SetTitle sets value of Title conditional field.
func ( *StarsSubscription) ( string) {
	.Flags.Set(4)
	.Title = 
}

// GetTitle returns value of Title conditional field and
// boolean which is true if field was set.
func ( *StarsSubscription) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .Title, true
}

// SetPhoto sets value of Photo conditional field.
func ( *StarsSubscription) ( WebDocumentClass) {
	.Flags.Set(5)
	.Photo = 
}

// GetPhoto returns value of Photo conditional field and
// boolean which is true if field was set.
func ( *StarsSubscription) () ( WebDocumentClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(5) {
		return , false
	}
	return .Photo, true
}

// SetInvoiceSlug sets value of InvoiceSlug conditional field.
func ( *StarsSubscription) ( string) {
	.Flags.Set(6)
	.InvoiceSlug = 
}

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