File size: 891 Bytes
5a22efd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | package usagebased
import (
"fmt"
"slices"
"github.com/openmeterio/openmeter/pkg/models"
)
type RatingEngine string
const (
// RatingEngineDelta rates the current cumulative meter snapshot, subtracts
// already booked detailed lines, and books the remainder on the current run
// service period.
RatingEngineDelta RatingEngine = "delta"
// RatingEnginePeriodPreserving rates cumulative snapshots per service
// period and preserves correction lines on their original service periods.
RatingEnginePeriodPreserving RatingEngine = "period_preserving"
)
func (e RatingEngine) Values() []string {
return []string{
string(RatingEngineDelta),
string(RatingEnginePeriodPreserving),
}
}
func (e RatingEngine) Validate() error {
if !slices.Contains(e.Values(), string(e)) {
return models.NewGenericValidationError(fmt.Errorf("invalid rating engine: %s", e))
}
return nil
}
|