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 TestNewAPI(t *testing.T) {
	mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))

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

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

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

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

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

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

			api := initialize.NewAPI(*controllers)

			assert.NotNil(t, api)
		})
	})
}
