// Code generated by Wire. DO NOT EDIT.

//go:generate go run -mod=mod github.com/google/wire/cmd/wire
//go:build !wireinject
// +build !wireinject

package testhelpers

import (
	"github.com/chainloop-dev/chainloop/app/controlplane/internal/conf/controlplane/config/v1"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/auditor"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/authz"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/conf/controlplane/config/v1"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/data"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/policies"
	"github.com/chainloop-dev/chainloop/app/controlplane/plugins/sdk/v1"
	"github.com/chainloop-dev/chainloop/internal/robotaccount/cas"
	"github.com/chainloop-dev/chainloop/pkg/blobmanager"
	"github.com/chainloop-dev/chainloop/pkg/credentials"
	"github.com/go-kratos/kratos/v2/log"
	"github.com/nats-io/nats.go"
	"testing"
)

import (
	_ "github.com/lib/pq"
)

// Injectors from wire.go:

// wireTestData init testing data
func WireTestData(testDatabase *TestDatabase, t *testing.T, logger log.Logger, readerWriter credentials.ReaderWriter, builder *robotaccount.Builder, auth *conf.Auth, bootstrap *conf.Bootstrap, arg []*v1.OnboardingSpec, availablePlugins sdk.AvailablePlugins, providers backend.Providers) (*TestingUseCases, func(), error) {
	confData := NewConfData(testDatabase, t)
	databaseConfig := NewDataConfig(confData)
	dataData, cleanup, err := data.NewData(databaseConfig, logger)
	if err != nil {
		return nil, nil, err
	}
	groupRepo := data.NewGroupRepo(dataData, logger)
	membershipRepo := data.NewMembershipRepo(dataData, groupRepo, logger)
	organizationRepo := data.NewOrganizationRepo(dataData, logger)
	casBackendRepo := data.NewCASBackendRepo(dataData, logger)
	bootstrap_CASServer := NewCASBackendConfig()
	casServerDefaultOpts := NewCASServerOptions(bootstrap_CASServer)
	conn, err := newNatsConnection()
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	auditLogPublisher, err := auditor.NewAuditLogPublisher(conn, logger)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	auditorUseCase := biz.NewAuditorUseCase(auditLogPublisher, logger)
	casBackendUseCase, err := biz.NewCASBackendUseCase(casBackendRepo, readerWriter, providers, casServerDefaultOpts, auditorUseCase, logger)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	integrationRepo := data.NewIntegrationRepo(dataData, logger)
	integrationAttachmentRepo := data.NewIntegrationAttachmentRepo(dataData, logger)
	workflowRepo := data.NewWorkflowRepo(dataData, logger)
	newIntegrationUseCaseOpts := &biz.NewIntegrationUseCaseOpts{
		IRepo:   integrationRepo,
		IaRepo:  integrationAttachmentRepo,
		WfRepo:  workflowRepo,
		CredsRW: readerWriter,
		Logger:  logger,
	}
	integrationUseCase := biz.NewIntegrationUseCase(newIntegrationUseCaseOpts)
	organizationUseCase := biz.NewOrganizationUseCase(organizationRepo, casBackendUseCase, auditorUseCase, integrationUseCase, membershipRepo, arg, logger)
	userRepo := data.NewUserRepo(dataData, logger)
	membershipUseCase := biz.NewMembershipUseCase(membershipRepo, organizationUseCase, auditorUseCase, userRepo, logger)
	workflowContractRepo := data.NewWorkflowContractRepo(dataData, logger)
	v := NewPolicyProviderConfig(bootstrap)
	registry, err := policies.NewRegistry(logger, v...)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	workflowContractUseCase := biz.NewWorkflowContractUseCase(workflowContractRepo, registry, auditorUseCase, logger)
	projectsRepo := data.NewProjectsRepo(dataData, logger)
	workflowUseCase := biz.NewWorkflowUsecase(workflowRepo, projectsRepo, workflowContractUseCase, auditorUseCase, membershipUseCase, logger)
	workflowRunRepo := data.NewWorkflowRunRepo(dataData, logger)
	signingUseCase, err := biz.NewChainloopSigningUseCase(bootstrap, logger)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	workflowRunUseCase, err := biz.NewWorkflowRunUseCase(workflowRunRepo, workflowRepo, signingUseCase, auditorUseCase, logger)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	v2 := NewPromSpec()
	orgMetricsRepo := data.NewOrgMetricsRepo(dataData, logger)
	orgMetricsUseCase, err := biz.NewOrgMetricsUseCase(orgMetricsRepo, organizationRepo, workflowUseCase, logger)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	prometheusUseCase := biz.NewPrometheusUseCase(v2, organizationUseCase, orgMetricsUseCase, logger)
	allowList := newAuthAllowList(bootstrap)
	userAccessSyncerUseCase := biz.NewUserAccessSyncerUseCase(logger, userRepo, allowList)
	newUserUseCaseParams := &biz.NewUserUseCaseParams{
		UserRepo:            userRepo,
		MembershipUseCase:   membershipUseCase,
		OrganizationUseCase: organizationUseCase,
		OnboardingConfig:    arg,
		Logger:              logger,
		AuditorUseCase:      auditorUseCase,
		UserAccessSyncer:    userAccessSyncerUseCase,
	}
	userUseCase := biz.NewUserUseCase(newUserUseCaseParams)
	robotAccountRepo := data.NewRobotAccountRepo(dataData, logger)
	robotAccountUseCase := biz.NewRootAccountUseCase(robotAccountRepo, workflowRepo, auth, logger)
	casMappingRepo := data.NewCASMappingRepo(dataData, casBackendRepo, logger)
	casMappingUseCase := biz.NewCASMappingUseCase(casMappingRepo, membershipUseCase, logger)
	orgInvitationRepo := data.NewOrgInvitation(dataData, logger)
	orgInvitationUseCase, err := biz.NewOrgInvitationUseCase(orgInvitationRepo, membershipRepo, userRepo, auditorUseCase, groupRepo, projectsRepo, logger)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	referrerRepo := data.NewReferrerRepo(dataData, workflowRepo, logger)
	referrerSharedIndex := _wireReferrerSharedIndexValue
	referrerUseCase, err := biz.NewReferrerUseCase(referrerRepo, workflowRepo, membershipUseCase, referrerSharedIndex, logger)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	apiTokenRepo := data.NewAPITokenRepo(dataData, logger)
	apiTokenJWTConfig := newJWTConfig(auth)
	config := authzConfig()
	enforcer, err := authz.NewDatabaseEnforcer(databaseConfig, config)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	apiTokenUseCase, err := biz.NewAPITokenUseCase(apiTokenRepo, apiTokenJWTConfig, enforcer, organizationUseCase, auditorUseCase, logger)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	attestationStateRepo := data.NewAttestationStateRepo(dataData, logger)
	attestationStateUseCase, err := biz.NewAttestationStateUseCase(attestationStateRepo, workflowRunRepo)
	if err != nil {
		cleanup()
		return nil, nil, err
	}
	projectVersionRepo := data.NewProjectVersionRepo(dataData, logger)
	projectVersionUseCase := biz.NewProjectVersionUseCase(projectVersionRepo, logger)
	groupUseCase := biz.NewGroupUseCase(logger, groupRepo, membershipRepo, userRepo, orgInvitationUseCase, auditorUseCase, orgInvitationRepo, enforcer, membershipUseCase)
	projectUseCase := biz.NewProjectsUseCase(logger, projectsRepo, membershipRepo, auditorUseCase, groupUseCase, membershipUseCase, orgInvitationUseCase, orgInvitationRepo, enforcer)
	testingRepos := &TestingRepos{
		Membership:        membershipRepo,
		Referrer:          referrerRepo,
		Workflow:          workflowRepo,
		WorkflowRunRepo:   workflowRunRepo,
		AttestationState:  attestationStateRepo,
		OrganizationRepo:  organizationRepo,
		GroupRepo:         groupRepo,
		OrgInvitationRepo: orgInvitationRepo,
	}
	testingUseCases := &TestingUseCases{
		DB:                     testDatabase,
		Data:                   dataData,
		L:                      logger,
		Membership:             membershipUseCase,
		CASBackend:             casBackendUseCase,
		Integration:            integrationUseCase,
		Organization:           organizationUseCase,
		WorkflowContract:       workflowContractUseCase,
		Workflow:               workflowUseCase,
		WorkflowRun:            workflowRunUseCase,
		Prometheus:             prometheusUseCase,
		User:                   userUseCase,
		RobotAccount:           robotAccountUseCase,
		RegisteredIntegrations: availablePlugins,
		CASMapping:             casMappingUseCase,
		OrgInvitation:          orgInvitationUseCase,
		Referrer:               referrerUseCase,
		APIToken:               apiTokenUseCase,
		Enforcer:               enforcer,
		AttestationState:       attestationStateUseCase,
		ProjectVersion:         projectVersionUseCase,
		Project:                projectUseCase,
		OrgMetrics:             orgMetricsUseCase,
		Group:                  groupUseCase,
		Repos:                  testingRepos,
	}
	return testingUseCases, func() {
		cleanup()
	}, nil
}

var (
	_wireReferrerSharedIndexValue = &conf.ReferrerSharedIndex{}
)

// wire.go:

func authzConfig() *authz.Config {
	return &authz.Config{ManagedResources: authz.ManagedResources, RolesMap: authz.RolesMap}
}

func newJWTConfig(conf2 *conf.Auth) *biz.APITokenJWTConfig {
	return &biz.APITokenJWTConfig{
		SymmetricHmacKey: conf2.GeneratedJwsHmacSecret,
	}
}

// Connection to nats is optional, if not configured, pubsub will be disabled
func newNatsConnection() (*nats.Conn, error) {
	return nil, nil
}

func newAuthAllowList(conf2 *conf.Bootstrap) *v1.AllowList {
	return conf2.Auth.GetAllowList()
}
