40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/tech/sendico/billing/fees/storage/model"
|
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
)
|
|
|
|
type storageError string
|
|
|
|
func (e storageError) Error() string {
|
|
return string(e)
|
|
}
|
|
|
|
var (
|
|
// ErrFeePlanNotFound indicates that a requested fee plan does not exist.
|
|
ErrFeePlanNotFound = storageError("billing.fees.storage: fee plan not found")
|
|
// ErrDuplicateFeePlan indicates that a unique plan constraint was violated.
|
|
ErrDuplicateFeePlan = storageError("billing.fees.storage: duplicate fee plan")
|
|
// ErrConflictingFeePlans indicates multiple active plans matched a query.
|
|
ErrConflictingFeePlans = storageError("billing.fees.storage: conflicting fee plans")
|
|
)
|
|
|
|
// Repository defines the root storage contract for the fees service.
|
|
type Repository interface {
|
|
Ping(ctx context.Context) error
|
|
Plans() PlansStore
|
|
}
|
|
|
|
// PlansStore exposes persistence operations for fee plans.
|
|
type PlansStore interface {
|
|
Create(ctx context.Context, plan *model.FeePlan) error
|
|
Update(ctx context.Context, plan *model.FeePlan) error
|
|
Get(ctx context.Context, planRef primitive.ObjectID) (*model.FeePlan, error)
|
|
// Legacy helper that now prefers an org plan and falls back to a global plan.
|
|
GetActivePlan(ctx context.Context, orgRef primitive.ObjectID, at time.Time) (*model.FeePlan, error)
|
|
}
|