light modification
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
)
|
||||
|
||||
type PricingProfileITF interface {
|
||||
GetID() string
|
||||
GetPrice(quantity float64, val float64, start time.Time, end time.Time, params ...string) (float64, error)
|
||||
IsPurchased() bool
|
||||
GetOverrideStrategyValue() int
|
||||
@@ -20,16 +19,11 @@ const (
|
||||
)
|
||||
|
||||
type AccessPricingProfile[T Strategy] struct { // only use for acces such as : DATA && PROCESSING
|
||||
ID string `json:"id,omitempty" bson:"id,omitempty"` // ID is the ID of the pricing
|
||||
Pricing PricingStrategy[T] `json:"price,omitempty" bson:"price,omitempty"` // Price is the price of the resource
|
||||
Pricing PricingStrategy[T] `json:"pricing,omitempty" bson:"pricing,omitempty"` // Price is the price of the resource
|
||||
DefaultRefund RefundType `json:"default_refund" bson:"default_refund"` // DefaultRefund is the default refund type of the pricing
|
||||
RefundRatio int32 `json:"refund_ratio" bson:"refund_ratio" default:"0"` // RefundRatio is the refund ratio if missing
|
||||
}
|
||||
|
||||
func (b *AccessPricingProfile[T]) GetID() string {
|
||||
return b.ID
|
||||
}
|
||||
|
||||
func (b *AccessPricingProfile[T]) GetOverrideStrategyValue() int {
|
||||
return -1
|
||||
}
|
||||
@@ -50,9 +44,9 @@ type ExploitPricingProfile[T Strategy] struct { // only use for exploit such as
|
||||
AccessPricingProfile[T]
|
||||
AdditionnalRefundTypes []RefundType `json:"refund_types" bson:"refund_types"` // RefundTypes is the refund types of the pricing
|
||||
|
||||
PrivilegeStrategy ExploitPrivilegeStrategy `json:"privilege_strategy,omitempty" bson:"privilege_strategy,omitempty"` // Strategy is the strategy of the pricing
|
||||
GarantedDelaySecond uint
|
||||
PrivilegeStrategy ExploitPrivilegeStrategy `json:"privilege_strategy,omitempty" bson:"privilege_strategy,omitempty"` // Strategy is the strategy of the pricing
|
||||
GarantedDelaySecond uint `json:"garanted_delay_second,omitempty" bson:"garanted_delay_second,omitempty"` // GarantedDelaySecond is the garanted delay of the pricing
|
||||
|
||||
Exceeding bool
|
||||
Exceeding bool `json:"exceeding" bson:"exceeding"` // Exceeding is the exceeding of the bill
|
||||
ExceedingRatio int32 `json:"exceeding_ratio" bson:"exceeding_ratio" default:"0"` // ExceedingRatio is the exceeding ratio of the bill
|
||||
}
|
||||
|
@@ -85,35 +85,14 @@ func BookingEstimation(t TimePricingStrategy, price float64, locationDurationInS
|
||||
return 0, errors.New("Pricing strategy not found")
|
||||
}
|
||||
|
||||
// hmmmm
|
||||
type PricingStrategy[T Strategy] struct {
|
||||
Price float64 `json:"Price" bson:"Price" default:"0"` // Price is the Price of the pricing
|
||||
Price float64 `json:"price" bson:"price" default:"0"` // Price is the Price of the pricing
|
||||
Currency string `json:"currency" bson:"currency" default:"USD"` // Currency is the currency of the pricing
|
||||
BuyingStrategy BuyingStrategy `json:"buying_strategy" bson:"buying_strategy" default:"0"` // BuyingStrategy is the buying strategy of the pricing
|
||||
TimePricingStrategy TimePricingStrategy `json:"time_pricing_strategy" bson:"time_pricing_strategy" default:"0"` // TimePricingStrategy is the time pricing strategy of the pricing
|
||||
OverrideStrategy T `json:"override_strategy" bson:"override_strategy" default:"-1"` // Modulation is the modulation of the pricing
|
||||
}
|
||||
|
||||
func (p PricingStrategy[T]) SetStrategy(Price float64, BuyingStrategy BuyingStrategy, TimePricingStrategy TimePricingStrategy) error {
|
||||
if TimePricingStrategy == ONCE && (BuyingStrategy != UNLIMITED || BuyingStrategy != PAY_PER_USE) {
|
||||
return errors.New("time pricing strategy can only be set to ONCE if buying strategy is UNLIMITED or PAY_PER_USE")
|
||||
} else if BuyingStrategy == SUBSCRIPTION && (TimePricingStrategy == ONCE) {
|
||||
return errors.New("subscription duration in second must be set if buying strategy is SUBSCRIPTION")
|
||||
}
|
||||
p.Price = Price
|
||||
p.BuyingStrategy = BuyingStrategy
|
||||
p.TimePricingStrategy = TimePricingStrategy
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p PricingStrategy[T]) SetSpecificPerUseStrategy(strategy T) error {
|
||||
if p.BuyingStrategy == UNLIMITED {
|
||||
return errors.New("UNLIMITED buying strategy can't have a specific strategy, Price is set on buying")
|
||||
}
|
||||
p.OverrideStrategy = strategy
|
||||
return nil
|
||||
}
|
||||
|
||||
// QUANTITY can be how many of gb core per example
|
||||
func (p PricingStrategy[T]) GetPrice(amountOfData float64, bookingTimeDuration float64, start time.Time, end *time.Time) (float64, error) {
|
||||
if p.BuyingStrategy == SUBSCRIPTION {
|
||||
return BookingEstimation(p.GetTimePricingStrategy(), p.Price*float64(amountOfData), bookingTimeDuration, start, end)
|
||||
|
Reference in New Issue
Block a user