package repository

import "context"

// SourceIPCount holds the count of zero_rent_records for a single source IP.
type SourceIPCount struct {
	SourceIP string
	Count    int64
}

// ZeroRentRecordRepository manages the mapping between cluster IDs and their encrypted
// secrets generated when a cluster is rented from a shadow pool.
type ZeroRentRecordRepository interface {
	// Upsert stores or updates the encrypted secret for the given cluster ID.
	// Because ClusterID is a unique key, calling Upsert a second time for the
	// same cluster replaces the existing secret.
	// sourceIP is the client's source IP address; tag is an optional tag from the request,
	// truncated to 256 characters before storage.
	Upsert(ctx context.Context, clusterId uint64, encryptedSecret string, sourceIP string, tag string) error

	// GetByClusterID returns the encrypted secret associated with the given cluster ID.
	// Returns gorm.ErrRecordNotFound when no record exists.
	GetByClusterID(ctx context.Context, clusterId uint64) (string, error)

	// CountBySourceIP returns the top-n source IPs ordered by their record count (descending).
	// Only non-deleted records are considered. limit specifies the maximum number of entries to return.
	CountBySourceIP(ctx context.Context, limit int) ([]SourceIPCount, error)
}
