package usecase_helpers

import (
	"github.com/fiskerinc/cloud-services/pkg/common"
	"github.com/fiskerinc/cloud-services/pkg/db/queries"
)

func NewECUKeys(eccKeys queries.EccKeysInterface) *EcuKeys {
	return &EcuKeys{
		eccKeys: eccKeys,
	}
}

type EcuKeys struct {
	eccKeys queries.EccKeysInterface
}

func (e EcuKeys) AddECUECCKeys(manifest *common.UpdateManifest) error {
	ecus := manifest.GetECUs()
	keys, err := e.eccKeys.SelectPrivateKeysByECUsEnv(ecus, manifest.Env)
	if err != nil {
		return err
	}

	manifest.AddECUECCKeys(keys)

	return nil
}
