package domain

import "context"

type Repository interface {
	// ReservePlatform atomically guards both limits and increments one monthly counter document.
	// A negative limit means unlimited. BYOK must never call this operation.
	ReservePlatform(ctx context.Context, uid int64, monthKey, meter string, cost, totalLimit, meterLimit int) error
	// ReleasePlatform gives back a reservation whose call never happened. It is guarded so a
	// counter can never drop below zero, and is a no-op when there is nothing left to refund
	// (e.g. the month already rolled over), so callers may retry it safely.
	ReleasePlatform(ctx context.Context, uid int64, monthKey, meter string, cost int) error
	GetMonthlyCounter(ctx context.Context, uid int64, monthKey string) (*MonthlyCounter, error)

	InsertEvent(ctx context.Context, e *Event) error
	ListEvents(ctx context.Context, uid int64, monthKey, keyMode string, limit int) ([]*Event, error)
	ListEventsAll(ctx context.Context, monthKey string, limit int) ([]*Event, error)
	ListEventsRange(ctx context.Context, fromNano, toExclusiveNano int64) ([]*Event, error)

	GetPrefs(ctx context.Context, uid int64) (*MemberPrefs, error)
	SavePrefs(ctx context.Context, p *MemberPrefs) error

	InsertPurchase(ctx context.Context, p *Purchase) error
	ListPurchases(ctx context.Context, uid int64, limit int) ([]*Purchase, error)
}
