// Manager: the thread-safe multi-version snapshot registry (the Go port of
// the RustyChickpeas manager layer). Snapshots are immutable, so the
// registry is a mutex-guarded map of shared pointers.

package chickpeas

import 

// LatestVersion is the registry key AddSnapshot uses for a snapshot that
// carries no version string.
const LatestVersion = "latest"

// Manager holds named immutable snapshots.
type Manager struct {
	mu        sync.RWMutex
	snapshots map[string]*Snapshot
}

// NewManager returns an empty registry.
func () *Manager {
	return &Manager{snapshots: map[string]*Snapshot{}}
}

// AddSnapshot registers g under its own version string, or LatestVersion
// when it has none, replacing any previous snapshot under that key.
func ( *Manager) ( *Snapshot) {
	,  := .Version()
	if ! ||  == "" {
		 = LatestVersion
	}
	.AddSnapshotWithVersion(, )
}

// AddSnapshotWithVersion registers g under an explicit version key.
func ( *Manager) ( string,  *Snapshot) {
	.mu.Lock()
	defer .mu.Unlock()
	.snapshots[] = 
}

// Snapshot returns the snapshot registered under version; ok is false when
// absent.
func ( *Manager) ( string) (*Snapshot, bool) {
	.mu.RLock()
	defer .mu.RUnlock()
	,  := .snapshots[]
	return , 
}

// Versions lists the registered version keys (unordered).
func ( *Manager) () []string {
	.mu.RLock()
	defer .mu.RUnlock()
	 := make([]string, 0, len(.snapshots))
	for  := range .snapshots {
		 = append(, )
	}
	return 
}

// RemoveSnapshot drops the snapshot under version, reporting whether one
// was present.
func ( *Manager) ( string) bool {
	.mu.Lock()
	defer .mu.Unlock()
	,  := .snapshots[]
	delete(.snapshots, )
	return 
}

// Len is the number of registered snapshots.
func ( *Manager) () int {
	.mu.RLock()
	defer .mu.RUnlock()
	return len(.snapshots)
}

// Clear drops every registered snapshot.
func ( *Manager) () {
	.mu.Lock()
	defer .mu.Unlock()
	clear(.snapshots)
}