package stats

import (
	"sync"
	"time"
)

// NewInteger creates a new Integer StatsObject with the given name and
// returns a pointer to it.
func NewInteger(name string) *Integer {
	lock.Lock()
	defer lock.Unlock()

	node := findNodeLocked(name, true)
	i := Integer{value: 0}
	node.object = &i
	return &i
}

// Integer implements the StatsObject interface.
type Integer struct {
	mu         sync.RWMutex
	lastUpdate time.Time
	value      int64
}

// Set sets the value of the object.
func (i *Integer) Set(value int64) {
	i.mu.Lock()
	defer i.mu.Unlock()
	i.lastUpdate = time.Now()
	i.value = value
}

// Incr increments the value of the object.
func (i *Integer) Incr(delta int64) {
	i.mu.Lock()
	defer i.mu.Unlock()
	i.value += delta
	i.lastUpdate = time.Now()
}

// LastUpdate returns the time at which the object was last updated.
func (i Integer) LastUpdate() time.Time {
	i.mu.RLock()
	defer i.mu.RUnlock()
	return i.lastUpdate
}

// Value returns the current value of the object.
func (i Integer) Value() interface{} {
	i.mu.RLock()
	defer i.mu.RUnlock()
	return i.value
}
