add sets up
This commit is contained in:
@@ -9,7 +9,8 @@ import (
|
||||
type PricedItemITF interface {
|
||||
GetID() string
|
||||
GetType() tools.DataType
|
||||
IsPurchased() bool
|
||||
IsPurchasable() bool
|
||||
IsBooked() bool
|
||||
GetCreatorID() string
|
||||
GetLocationStart() *time.Time
|
||||
SetLocationStart(start time.Time)
|
||||
|
||||
@@ -6,7 +6,8 @@ import (
|
||||
|
||||
type PricingProfileITF interface {
|
||||
GetPrice(quantity float64, val float64, start time.Time, end time.Time, params ...string) (float64, error)
|
||||
IsPurchased() bool
|
||||
IsPurchasable() bool
|
||||
IsBooked() bool
|
||||
GetOverrideStrategyValue() int
|
||||
}
|
||||
|
||||
|
||||
@@ -7,21 +7,65 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type BillingStrategy int // BAM BAM
|
||||
|
||||
// should except... on
|
||||
const (
|
||||
BILL_ONCE BillingStrategy = iota // is a permanent buying ( predictible )
|
||||
BILL_PER_WEEK
|
||||
BILL_PER_MONTH
|
||||
BILL_PER_YEAR
|
||||
)
|
||||
|
||||
func (t BillingStrategy) IsBillingStrategyAllowed(bs int) (BillingStrategy, bool) {
|
||||
switch t {
|
||||
case BILL_ONCE:
|
||||
return BILL_ONCE, bs == 0
|
||||
case BILL_PER_WEEK:
|
||||
case BILL_PER_MONTH:
|
||||
case BILL_PER_YEAR:
|
||||
return t, bs != 0
|
||||
}
|
||||
return t, false
|
||||
}
|
||||
|
||||
func (t BillingStrategy) String() string {
|
||||
return [...]string{"BILL_ONCE", "BILL_PER_WEEK", "BILL_PER_MONTH", "BILL_PER_YEAR"}[t]
|
||||
}
|
||||
|
||||
func BillingStrategyList() []BillingStrategy {
|
||||
return []BillingStrategy{BILL_ONCE, BILL_PER_WEEK, BILL_PER_MONTH, BILL_PER_YEAR}
|
||||
}
|
||||
|
||||
type BuyingStrategy int
|
||||
|
||||
// should except... on
|
||||
const (
|
||||
UNLIMITED BuyingStrategy = iota
|
||||
SUBSCRIPTION
|
||||
PAY_PER_USE
|
||||
PERMANENT BuyingStrategy = iota // is a permanent buying ( predictible )
|
||||
UNDEFINED_SUBSCRIPTION // a endless subscription ( unpredictible )
|
||||
SUBSCRIPTION // a defined subscription ( predictible )
|
||||
// PAY_PER_USE // per request. ( unpredictible )
|
||||
)
|
||||
|
||||
func (t BuyingStrategy) String() string {
|
||||
return [...]string{"UNLIMITED", "SUBSCRIPTION", "PAY PER USE"}[t]
|
||||
return [...]string{"PERMANENT", "UNDEFINED_SUBSCRIPTION", "SUBSCRIPTION"}[t]
|
||||
}
|
||||
|
||||
func (t BuyingStrategy) IsBillingStrategyAllowed(bs BillingStrategy) (BillingStrategy, bool) {
|
||||
switch t {
|
||||
case PERMANENT:
|
||||
return BILL_ONCE, bs == BILL_ONCE
|
||||
case UNDEFINED_SUBSCRIPTION:
|
||||
return BILL_PER_MONTH, bs != BILL_ONCE
|
||||
case SUBSCRIPTION:
|
||||
/*case PAY_PER_USE:
|
||||
return bs, true*/
|
||||
}
|
||||
return bs, false
|
||||
}
|
||||
|
||||
func BuyingStrategyList() []BuyingStrategy {
|
||||
return []BuyingStrategy{UNLIMITED, SUBSCRIPTION, PAY_PER_USE}
|
||||
return []BuyingStrategy{PERMANENT, UNDEFINED_SUBSCRIPTION, SUBSCRIPTION}
|
||||
}
|
||||
|
||||
type Strategy interface {
|
||||
@@ -118,7 +162,7 @@ type PricingStrategy[T Strategy] struct {
|
||||
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)
|
||||
} else if p.BuyingStrategy == UNLIMITED {
|
||||
} else if p.BuyingStrategy == PERMANENT {
|
||||
return p.Price, nil
|
||||
}
|
||||
return p.Price * float64(amountOfData), nil
|
||||
|
||||
@@ -15,9 +15,9 @@ func (d DummyStrategy) GetStrategy() string { return "DUMMY" }
|
||||
func (d DummyStrategy) GetStrategyValue() int { return int(d) }
|
||||
|
||||
func TestBuyingStrategy_String(t *testing.T) {
|
||||
assert.Equal(t, "UNLIMITED", pricing.UNLIMITED.String())
|
||||
assert.Equal(t, "UNLIMITED", pricing.PERMANENT.String())
|
||||
assert.Equal(t, "SUBSCRIPTION", pricing.SUBSCRIPTION.String())
|
||||
assert.Equal(t, "PAY PER USE", pricing.PAY_PER_USE.String())
|
||||
//assert.Equal(t, "PAY PER USE", pricing.PAY_PER_USE.String())
|
||||
}
|
||||
|
||||
func TestBuyingStrategyList(t *testing.T) {
|
||||
@@ -116,13 +116,13 @@ func TestPricingStrategy_GetPrice(t *testing.T) {
|
||||
assert.True(t, p > 0)
|
||||
|
||||
// UNLIMITED case
|
||||
ps.BuyingStrategy = pricing.UNLIMITED
|
||||
ps.BuyingStrategy = pricing.PERMANENT
|
||||
p, err = ps.GetPrice(10, 0, start, &end)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 5.0, p)
|
||||
|
||||
// PAY_PER_USE case
|
||||
ps.BuyingStrategy = pricing.PAY_PER_USE
|
||||
//ps.BuyingStrategy = pricing.PAY_PER_USE
|
||||
p, err = ps.GetPrice(3, 0, start, &end)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 15.0, p)
|
||||
|
||||
Reference in New Issue
Block a user