package services

import (
	"sync"

	"github.com/fiskerinc/cloud-services/pkg/digitaltwin"
)

// There is no need to recreate the digital twin sender every time we send a digital twin
// so keeping a reference here

var sendDigitalTwin *digitaltwin.SendDigitalTwin
var sendDigitalTwinOnce sync.Once

func GetSendDigitalTwin()(*digitaltwin.SendDigitalTwin){
	sendDigitalTwinOnce.Do(func(){
		if sendDigitalTwin == nil {
			notSureWhyIcantTakeAddress := digitaltwin.NewSendDigitalTwin(RedisClientPool(), GetDB().GetCars())
			sendDigitalTwin = &notSureWhyIcantTakeAddress
		}
	})
	return sendDigitalTwin
}