package storage

import (
	"time"

	"git.sp4ke.com/sp4ke/bit4sat/config"
	"github.com/speps/go-hashids"
)

var ShortHD *hashids.HashIDData
var LongHD *hashids.HashIDData

func GetShortId() (string, error) {
	hd, err := hashids.NewWithData(ShortHD)
	if err != nil {
		return "", err
	}

	now := int64(time.Now().UnixNano())
	short, err := hd.EncodeInt64([]int64{now})
	if err != nil {
		return "", err
	}

	return short, nil

}

func GetLongId() (string, error) {

	hd, err := hashids.NewWithData(LongHD)
	if err != nil {
		return "", err
	}

	now := int64(time.Now().UnixNano())
	long, err := hd.EncodeInt64([]int64{now})
	if err != nil {
		return "", err
	}

	return long, nil

}

func init() {
	ShortHD = hashids.NewData()
	ShortHD.Salt = config.ShortIdSalt
	ShortHD.MinLength = 8

	LongHD = hashids.NewData()
	LongHD.Salt = config.ShortIdSalt
	LongHD.MinLength = 32
}
