// Package inviteemailratelimit provides rate limiting for invitation emails
// using Cassandra counter tables.
package inviteemailratelimit

import (
	"context"
	"time"

	"github.com/gocql/gocql"
	"go.uber.org/zap"

	"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/config"
)

// Repository defines the interface for invite email rate limiting
type Repository interface {
	// GetDailyEmailCount returns the number of invitation emails sent by a user today
	GetDailyEmailCount(ctx context.Context, userID gocql.UUID, date time.Time) (int, error)
	// IncrementDailyEmailCount increments the counter for emails sent today
	IncrementDailyEmailCount(ctx context.Context, userID gocql.UUID, date time.Time) error
}

type repositoryImpl struct {
	logger  *zap.Logger
	session *gocql.Session
}

// NewRepository creates a new invite email rate limit repository
func NewRepository(appCfg *config.Configuration, session *gocql.Session, logger *zap.Logger) Repository {
	logger = logger.Named("InviteEmailRateLimitRepository")

	return &repositoryImpl{
		logger:  logger,
		session: session,
	}
}
