package tid

import "github.com/bluesky-social/indigo/atproto/syntax"

var TIDClock = syntax.NewTIDClock(0)

func TID() string {
	return TIDClock.Next().String()
}

type MonotonicGenerator struct {
	lastMicros int64
}

func (g *MonotonicGenerator) FromNanos(unixNanos int64) string {
	micros := unixNanos / 1000
	if micros <= g.lastMicros {
		micros = g.lastMicros + 1
	}
	g.lastMicros = micros
	return string(syntax.NewTID(micros, 0))
}
