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

// StarRefProgram represents TL type `starRefProgram#dd0c66f2`.
// Info about an affiliate program offered by a bot¹
//
// Links:
//  1. https://core.telegram.org/api/bots/referrals
//
// See https://core.telegram.org/constructor/starRefProgram for reference.
type StarRefProgram struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// ID of the bot that offers the program
	BotID int64
	// An affiliate gets a commission of starRefProgram¹.commission_permille‰ Telegram
	// Stars² for every mini app transaction made by users they refer
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starRefProgram
	//  2) https://core.telegram.org/api/stars
	CommissionPermille int
	// An affiliate gets a commission for every mini app transaction made by users they refer
	// for duration_months months after a referral link is imported, starting the bot for
	// the first time
	//
	// Use SetDurationMonths and GetDurationMonths helpers.
	DurationMonths int
	// Point in time (Unix timestamp) when the affiliate program will be closed (optional, if
	// not set the affiliate program isn't scheduled to be closed)
	//
	// Use SetEndDate and GetEndDate helpers.
	EndDate int
	// The amount of daily revenue per user in Telegram Stars of the bot that created the
	// affiliate program. To obtain the approximated revenue per referred user, multiply this
	// value by commission_permille and divide by 1000.
	//
	// Use SetDailyRevenuePerUser and GetDailyRevenuePerUser helpers.
	DailyRevenuePerUser StarsAmountClass
}

// StarRefProgramTypeID is TL type id of StarRefProgram.
const StarRefProgramTypeID = 0xdd0c66f2

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

func ( *StarRefProgram) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.BotID == 0) {
		return false
	}
	if !(.CommissionPermille == 0) {
		return false
	}
	if !(.DurationMonths == 0) {
		return false
	}
	if !(.EndDate == 0) {
		return false
	}
	if !(.DailyRevenuePerUser == nil) {
		return false
	}

	return true
}

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

// FillFrom fills StarRefProgram from given interface.
func ( *StarRefProgram) ( interface {
	() ( int64)
	() ( int)
	() ( int,  bool)
	() ( int,  bool)
	() ( StarsAmountClass,  bool)
}) {
	.BotID = .()
	.CommissionPermille = .()
	if ,  := .();  {
		.DurationMonths = 
	}

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *StarRefProgram) () tdp.Type {
	 := tdp.Type{
		Name: "starRefProgram",
		ID:   StarRefProgramTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "BotID",
			SchemaName: "bot_id",
		},
		{
			Name:       "CommissionPermille",
			SchemaName: "commission_permille",
		},
		{
			Name:       "DurationMonths",
			SchemaName: "duration_months",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "EndDate",
			SchemaName: "end_date",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "DailyRevenuePerUser",
			SchemaName: "daily_revenue_per_user",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StarRefProgram) () {
	if !(.DurationMonths == 0) {
		.Flags.Set(0)
	}
	if !(.EndDate == 0) {
		.Flags.Set(1)
	}
	if !(.DailyRevenuePerUser == nil) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *StarRefProgram) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starRefProgram#dd0c66f2 as nil")
	}
	.PutID(StarRefProgramTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarRefProgram) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starRefProgram#dd0c66f2 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode starRefProgram#dd0c66f2: field flags: %w", )
	}
	.PutLong(.BotID)
	.PutInt(.CommissionPermille)
	if .Flags.Has(0) {
		.PutInt(.DurationMonths)
	}
	if .Flags.Has(1) {
		.PutInt(.EndDate)
	}
	if .Flags.Has(2) {
		if .DailyRevenuePerUser == nil {
			return fmt.Errorf("unable to encode starRefProgram#dd0c66f2: field daily_revenue_per_user is nil")
		}
		if  := .DailyRevenuePerUser.Encode();  != nil {
			return fmt.Errorf("unable to encode starRefProgram#dd0c66f2: field daily_revenue_per_user: %w", )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StarRefProgram) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starRefProgram#dd0c66f2 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode starRefProgram#dd0c66f2: field flags: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starRefProgram#dd0c66f2: field bot_id: %w", )
		}
		.BotID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starRefProgram#dd0c66f2: field commission_permille: %w", )
		}
		.CommissionPermille = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starRefProgram#dd0c66f2: field duration_months: %w", )
		}
		.DurationMonths = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starRefProgram#dd0c66f2: field end_date: %w", )
		}
		.EndDate = 
	}
	if .Flags.Has(2) {
		,  := DecodeStarsAmount()
		if  != nil {
			return fmt.Errorf("unable to decode starRefProgram#dd0c66f2: field daily_revenue_per_user: %w", )
		}
		.DailyRevenuePerUser = 
	}
	return nil
}

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

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

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

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

// SetEndDate sets value of EndDate conditional field.
func ( *StarRefProgram) ( int) {
	.Flags.Set(1)
	.EndDate = 
}

// GetEndDate returns value of EndDate conditional field and
// boolean which is true if field was set.
func ( *StarRefProgram) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .EndDate, true
}

// SetDailyRevenuePerUser sets value of DailyRevenuePerUser conditional field.
func ( *StarRefProgram) ( StarsAmountClass) {
	.Flags.Set(2)
	.DailyRevenuePerUser = 
}

// GetDailyRevenuePerUser returns value of DailyRevenuePerUser conditional field and
// boolean which is true if field was set.
func ( *StarRefProgram) () ( StarsAmountClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .DailyRevenuePerUser, true
}