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

// BotsUpdateStarRefProgramRequest represents TL type `bots.updateStarRefProgram#778b5ab3`.
// Create, edit or delete the affiliate program¹ of a bot we own
//
// Links:
//  1. https://core.telegram.org/api/bots/referrals
//
// See https://core.telegram.org/method/bots.updateStarRefProgram for reference.
type BotsUpdateStarRefProgramRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// The bot
	Bot InputUserClass
	// The permille commission rate: it indicates the share of Telegram Stars received by
	// affiliates for every transaction made by users they referred inside of the bot.    The
	// minimum and maximum values for this parameter are contained in the
	// starref_min_commission_permille¹ and starref_max_commission_permille² client
	// configuration parameters.   Can be 0 to terminate the affiliate program.  Both the
	// duration and the commission may only be raised after creation of the program: to lower
	// them, the program must first be terminated and a new one created.
	//
	// Links:
	//  1) https://core.telegram.org/api/config#starref-min-commission-permille
	//  2) https://core.telegram.org/api/config#starref-max-commission-permille
	CommissionPermille int
	// Indicates the duration of the affiliate program; if not set, there is no expiration
	// date.
	//
	// Use SetDurationMonths and GetDurationMonths helpers.
	DurationMonths int
}

// BotsUpdateStarRefProgramRequestTypeID is TL type id of BotsUpdateStarRefProgramRequest.
const BotsUpdateStarRefProgramRequestTypeID = 0x778b5ab3

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

func ( *BotsUpdateStarRefProgramRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Bot == nil) {
		return false
	}
	if !(.CommissionPermille == 0) {
		return false
	}
	if !(.DurationMonths == 0) {
		return false
	}

	return true
}

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

// FillFrom fills BotsUpdateStarRefProgramRequest from given interface.
func ( *BotsUpdateStarRefProgramRequest) ( interface {
	() ( InputUserClass)
	() ( int)
	() ( int,  bool)
}) {
	.Bot = .()
	.CommissionPermille = .()
	if ,  := .();  {
		.DurationMonths = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*BotsUpdateStarRefProgramRequest) () string {
	return "bots.updateStarRefProgram"
}

// TypeInfo returns info about TL type.
func ( *BotsUpdateStarRefProgramRequest) () tdp.Type {
	 := tdp.Type{
		Name: "bots.updateStarRefProgram",
		ID:   BotsUpdateStarRefProgramRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Bot",
			SchemaName: "bot",
		},
		{
			Name:       "CommissionPermille",
			SchemaName: "commission_permille",
		},
		{
			Name:       "DurationMonths",
			SchemaName: "duration_months",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *BotsUpdateStarRefProgramRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode bots.updateStarRefProgram#778b5ab3 as nil")
	}
	.PutID(BotsUpdateStarRefProgramRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *BotsUpdateStarRefProgramRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode bots.updateStarRefProgram#778b5ab3 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode bots.updateStarRefProgram#778b5ab3: field flags: %w", )
	}
	if .Bot == nil {
		return fmt.Errorf("unable to encode bots.updateStarRefProgram#778b5ab3: field bot is nil")
	}
	if  := .Bot.Encode();  != nil {
		return fmt.Errorf("unable to encode bots.updateStarRefProgram#778b5ab3: field bot: %w", )
	}
	.PutInt(.CommissionPermille)
	if .Flags.Has(0) {
		.PutInt(.DurationMonths)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *BotsUpdateStarRefProgramRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode bots.updateStarRefProgram#778b5ab3 to nil")
	}
	if  := .ConsumeID(BotsUpdateStarRefProgramRequestTypeID);  != nil {
		return fmt.Errorf("unable to decode bots.updateStarRefProgram#778b5ab3: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *BotsUpdateStarRefProgramRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode bots.updateStarRefProgram#778b5ab3 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode bots.updateStarRefProgram#778b5ab3: field flags: %w", )
		}
	}
	{
		,  := DecodeInputUser()
		if  != nil {
			return fmt.Errorf("unable to decode bots.updateStarRefProgram#778b5ab3: field bot: %w", )
		}
		.Bot = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode bots.updateStarRefProgram#778b5ab3: field commission_permille: %w", )
		}
		.CommissionPermille = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode bots.updateStarRefProgram#778b5ab3: field duration_months: %w", )
		}
		.DurationMonths = 
	}
	return nil
}

// GetBot returns value of Bot field.
func ( *BotsUpdateStarRefProgramRequest) () ( InputUserClass) {
	if  == nil {
		return
	}
	return .Bot
}

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

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

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

// BotsUpdateStarRefProgram invokes method bots.updateStarRefProgram#778b5ab3 returning error if any.
// Create, edit or delete the affiliate program¹ of a bot we own
//
// Links:
//  1. https://core.telegram.org/api/bots/referrals
//
// Possible errors:
//
//	400 BOT_INVALID: This is not a valid bot.
//	400 STARREF_AWAITING_END: The previous referral program was terminated less than 24 hours ago: further changes can be made after the date specified in userFull.starref_program.end_date.
//	400 STARREF_PERMILLE_INVALID: The specified commission_permille is invalid: the minimum and maximum values for this parameter are contained in the starref_min_commission_permille and starref_max_commission_permille client configuration parameters.
//	400 STARREF_PERMILLE_TOO_LOW: The specified commission_permille is too low: the minimum and maximum values for this parameter are contained in the starref_min_commission_permille and starref_max_commission_permille client configuration parameters.
//
// See https://core.telegram.org/method/bots.updateStarRefProgram for reference.
func ( *Client) ( context.Context,  *BotsUpdateStarRefProgramRequest) (*StarRefProgram, error) {
	var  StarRefProgram

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