add sets up
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user