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

// ConnectedBotStarRef represents TL type `connectedBotStarRef#19a13f71`.
// Info about an active affiliate program we have with a Mini App¹
//
// Links:
//  1. https://core.telegram.org/api/bots/referrals#becoming-an-affiliate
//
// See https://core.telegram.org/constructor/connectedBotStarRef for reference.
type ConnectedBotStarRef struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, this affiliation was revoked by the affiliate using payments
	// editConnectedStarRefBot¹, or by the affiliation program owner using bots
	// updateStarRefProgram²
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.editConnectedStarRefBot
	//  2) https://core.telegram.org/method/bots.updateStarRefProgram
	Revoked bool
	// Referral link¹ to be shared
	//
	// Links:
	//  1) https://core.telegram.org/api/links#referral-links
	URL string
	// When did we affiliate with bot_id
	Date int
	// ID of the mini app that created the affiliate program
	BotID int64
	// The number of Telegram Stars received by the affiliate for each 1000 Telegram Stars
	// received by bot_id
	CommissionPermille int
	// Number of months the program will be active; if not set, there is no expiration date.
	//
	// Use SetDurationMonths and GetDurationMonths helpers.
	DurationMonths int
	// The number of users that used the affiliate program
	Participants int64
	// The number of Telegram Stars that were earned by the affiliate program
	Revenue int64
}

// ConnectedBotStarRefTypeID is TL type id of ConnectedBotStarRef.
const ConnectedBotStarRefTypeID = 0x19a13f71

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

func ( *ConnectedBotStarRef) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Revoked == false) {
		return false
	}
	if !(.URL == "") {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.BotID == 0) {
		return false
	}
	if !(.CommissionPermille == 0) {
		return false
	}
	if !(.DurationMonths == 0) {
		return false
	}
	if !(.Participants == 0) {
		return false
	}
	if !(.Revenue == 0) {
		return false
	}

	return true
}

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

// FillFrom fills ConnectedBotStarRef from given interface.
func ( *ConnectedBotStarRef) ( interface {
	() ( bool)
	() ( string)
	() ( int)
	() ( int64)
	() ( int)
	() ( int,  bool)
	() ( int64)
	() ( int64)
}) {
	.Revoked = .()
	.URL = .()
	.Date = .()
	.BotID = .()
	.CommissionPermille = .()
	if ,  := .();  {
		.DurationMonths = 
	}

	.Participants = .()
	.Revenue = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *ConnectedBotStarRef) () tdp.Type {
	 := tdp.Type{
		Name: "connectedBotStarRef",
		ID:   ConnectedBotStarRefTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Revoked",
			SchemaName: "revoked",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "URL",
			SchemaName: "url",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "BotID",
			SchemaName: "bot_id",
		},
		{
			Name:       "CommissionPermille",
			SchemaName: "commission_permille",
		},
		{
			Name:       "DurationMonths",
			SchemaName: "duration_months",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Participants",
			SchemaName: "participants",
		},
		{
			Name:       "Revenue",
			SchemaName: "revenue",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *ConnectedBotStarRef) () {
	if !(.Revoked == false) {
		.Flags.Set(1)
	}
	if !(.DurationMonths == 0) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *ConnectedBotStarRef) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode connectedBotStarRef#19a13f71 as nil")
	}
	.PutID(ConnectedBotStarRefTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ConnectedBotStarRef) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode connectedBotStarRef#19a13f71 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode connectedBotStarRef#19a13f71: field flags: %w", )
	}
	.PutString(.URL)
	.PutInt(.Date)
	.PutLong(.BotID)
	.PutInt(.CommissionPermille)
	if .Flags.Has(0) {
		.PutInt(.DurationMonths)
	}
	.PutLong(.Participants)
	.PutLong(.Revenue)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *ConnectedBotStarRef) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode connectedBotStarRef#19a13f71 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode connectedBotStarRef#19a13f71: field flags: %w", )
		}
	}
	.Revoked = .Flags.Has(1)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode connectedBotStarRef#19a13f71: field url: %w", )
		}
		.URL = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode connectedBotStarRef#19a13f71: field date: %w", )
		}
		.Date = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode connectedBotStarRef#19a13f71: field bot_id: %w", )
		}
		.BotID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode connectedBotStarRef#19a13f71: field commission_permille: %w", )
		}
		.CommissionPermille = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode connectedBotStarRef#19a13f71: field duration_months: %w", )
		}
		.DurationMonths = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode connectedBotStarRef#19a13f71: field participants: %w", )
		}
		.Participants = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode connectedBotStarRef#19a13f71: field revenue: %w", )
		}
		.Revenue = 
	}
	return nil
}

// SetRevoked sets value of Revoked conditional field.
func ( *ConnectedBotStarRef) ( bool) {
	if  {
		.Flags.Set(1)
		.Revoked = true
	} else {
		.Flags.Unset(1)
		.Revoked = false
	}
}

// GetRevoked returns value of Revoked conditional field.
func ( *ConnectedBotStarRef) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// GetURL returns value of URL field.
func ( *ConnectedBotStarRef) () ( string) {
	if  == nil {
		return
	}
	return .URL
}

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

// GetBotID returns value of BotID field.
func ( *ConnectedBotStarRef) () ( int64) {
	if  == nil {
		return
	}
	return .BotID
}

// GetCommissionPermille returns value of CommissionPermille field.
func ( *ConnectedBotStarRef) () ( int) {
	if  == nil {
		return
	}
	return .CommissionPermille
}

// SetDurationMonths sets value of DurationMonths conditional field.
func ( *ConnectedBotStarRef) ( int) {
	.Flags.Set(0)
	.DurationMonths = 
}

// GetDurationMonths returns value of DurationMonths conditional field and
// boolean which is true if field was set.
func ( *ConnectedBotStarRef) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .DurationMonths, true
}

// GetParticipants returns value of Participants field.
func ( *ConnectedBotStarRef) () ( int64) {
	if  == nil {
		return
	}
	return .Participants
}

// GetRevenue returns value of Revenue field.
func ( *ConnectedBotStarRef) () ( int64) {
	if  == nil {
		return
	}
	return .Revenue
}