package snowflake

import (
	"time"

	"github.com/bwmarrin/snowflake"
)

type Snow struct {
	*snowflake.Node
}

func New(opts ...Option) (*Snow, error) {
	opt := new(options)
	for _, o := range opts {
		o(opt)
	}

	res := new(Snow)

	st, err := time.Parse("2006-01-02", opt.startTime)
	if err != nil {
		return nil, err
	}

	snowflake.Epoch = st.UnixNano() / 1000000
	res.Node, err = snowflake.NewNode(opt.machineId)
	if err != nil {
		return nil, err
	}

	return res, nil
}

func (s *Snow) Gen() int64 {
	return s.Generate().Int64()
}
