package graph

import (
	"sync"

	"github.com/ClusterCockpit/cc-backend/internal/repository"
	cclog "github.com/ClusterCockpit/cc-lib/v2/ccLogger"
	"github.com/jmoiron/sqlx"
)

// This file will not be regenerated automatically.
//
// It serves as dependency injection for your app, add any dependencies you require here.
var (
	initOnce         sync.Once
	resolverInstance *Resolver
)

type Resolver struct {
	DB   *sqlx.DB
	Repo *repository.JobRepository
}

func Init() {
	initOnce.Do(func() {
		db := repository.GetConnection()
		resolverInstance = &Resolver{
			DB: db.DB, Repo: repository.GetJobRepository(),
		}
	})
}

func GetResolverInstance() *Resolver {
	if resolverInstance == nil {
		cclog.Fatal("Authentication module not initialized!")
	}

	return resolverInstance
}
