package manifestfingerprintparams

import (
	"sync"
	"time"

	"github.com/fiskerinc/cloud-services/pkg/utils/envtool"
)

var fpParams FingerprintParamer
var fpParamsOnce sync.Once

func SetFPParams(fpp FingerprintParamer) {
	fpParams = fpp
}

func GetFPParams() FingerprintParamer {
	fpParamsOnce.Do(func() {
		if fpParams == nil {
			fpParams = &FingerprintParams{
				serialNum: envtool.GetEnv("OTA_MANIFEST_SERIAL", "00000000000000000"),
			}
		}
	})

	return fpParams
}

type FingerprintParams struct {
	serialNum string
}

func (p *FingerprintParams) ManifestSerial() string {
	return p.serialNum
}

func (p *FingerprintParams) CurTime() time.Time {
	return time.Now().UTC()
}

var _ FingerprintParamer = &FingerprintParams{}

type FingerprintParamer interface {
	ManifestSerial() string
	CurTime() time.Time
}
