package ksuid

import (
	
	
	
)

// Sequence is a KSUID generator which produces a sequence of ordered KSUIDs
// from a seed.
//
// Up to 65536 KSUIDs can be generated by for a single seed.
//
// A typical usage of a Sequence looks like this:
//
//	seq := ksuid.Sequence{
//		Seed: ksuid.New(),
//	}
//	id, err := seq.Next()
//
// Sequence values are not safe to use concurrently from multiple goroutines.
type Sequence struct {
	// The seed is used as base for the KSUID generator, all generated KSUIDs
	// share the same leading 18 bytes of the seed.
	Seed  KSUID
	count uint32 // uint32 for overflow, only 2 bytes are used
}

// Next produces the next KSUID in the sequence, or returns an error if the
// sequence has been exhausted.
func ( *Sequence) () (KSUID, error) {
	 := .Seed // copy
	 := .count
	if  > math.MaxUint16 {
		return Nil, errors.New("too many IDs were generated")
	}
	.count++
	return withSequenceNumber(, uint16()), nil
}

// Bounds returns the inclusive min and max bounds of the KSUIDs that may be
// generated by the sequence. If all ids have been generated already then the
// returned min value is equal to the max.
func ( *Sequence) () ( KSUID,  KSUID) {
	 := .count
	if  > math.MaxUint16 {
		 = math.MaxUint16
	}
	return withSequenceNumber(.Seed, uint16()), withSequenceNumber(.Seed, math.MaxUint16)
}

func withSequenceNumber( KSUID,  uint16) KSUID {
	binary.BigEndian.PutUint16([len()-2:], )
	return 
}