package initialize_test

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/twmb/franz-go/pkg/kgo"
	"go.mongodb.org/mongo-driver/mongo/integration/mtest"
	"go.uber.org/zap"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/initialize"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
)

func TestNewControllers(t *testing.T) {
	mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))

	mt.Run("Контроллеры должны успешно инициализироваться", func(t *mtest.T) {
		logger := zap.New(zap.L().Core())

		assert.NotPanics(t, func() {
			clients := initialize.NewClients(initialize.ClientsDeps{
				Logger:                       logger,
				AuthURL:                      &models.AuthMicroserviceURL{},
				HubadminURL:                  &models.HubadminMicroserviceURL{},
				CurrencyURL:                  &models.CurrencyMicroserviceURL{},
				DiscountServiceConfiguration: &models.DiscountMicroserviceConfiguration{HostGRPC: "host"},
				PaymentServiceConfiguration:  &models.PaymentMicroserviceConfiguration{HostGRPC: "host"},
				VerificationURL:              &models.VerificationMicroserviceURL{Verification: ""},
				TemplategenURL:               &models.TemplategenMicroserviceURL{Templategen: ""},
			})

			repositories := initialize.NewRepositories(initialize.RepositoriesDeps{
				Logger:  logger,
				MongoDB: t.Client.Database("test"),
			})

			brokers := initialize.NewBrokers(initialize.BrokersDeps{
				Logger:       logger,
				TariffClient: &kgo.Client{},
			})

			services := initialize.NewServices(initialize.ServicesDeps{
				Logger:            logger,
				Clients:           clients,
				Repositories:      repositories,
				Brokers:           brokers,
				ConfigurationGRPC: &models.ConfigurationGRPC{Domen: "http://test:8080"},
			})

			controllers := initialize.NewControllers(initialize.ControllersDeps{
				Logger:   logger,
				Services: services,
			})

			assert.NotNil(t, controllers)
			assert.NotNil(t, controllers.AccountController)
			assert.NotNil(t, controllers.CurrencyController)
			assert.NotNil(t, controllers.CartController)
			assert.NotNil(t, controllers.HistoryController)
			assert.NotNil(t, controllers.WalletController)
		})
	})
}
