package initialize

import (
	"go.uber.org/zap"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/broker/tariff"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/callback"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/history"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/service/wallet"
	tb "gopkg.in/tucnak/telebot.v2"
)

type ServicesDeps struct {
	Logger            *zap.Logger
	Repositories      *Repositories
	Clients           *Clients
	Brokers           *Brokers
	ConfigurationGRPC *models.ConfigurationGRPC
	Notifier 					*tb.Bot
	NotificationChannel int64
	AdminURL 					string
}

type Services struct {
	HistoryService         *history.Service
	WalletService          *wallet.Service
	PaymentCallbackService *callback.PaymentCallbackService
	TariffBrokerService    *tariff.Service
}

func NewServices(deps ServicesDeps) *Services {
	historyService := history.New(history.Deps{
		Logger:     deps.Logger,
		Repository: deps.Repositories.HistoryRepository,
		AuthClient: deps.Clients.AuthClient,
	})

	walletService := wallet.New(wallet.Deps{
		Logger:             deps.Logger,
		Repository:         deps.Repositories.AccountRepository,
		CurrencyClient:     deps.Clients.CurrencyClient,
		VerificationClient: deps.Clients.VerificationClient,
		AuthClient:         deps.Clients.AuthClient,
		MailClient:         deps.Clients.MailClient,
		HistoryService:     historyService,
	})

	tariffBrokerService := tariff.New(tariff.Deps{
		Logger:   deps.Logger,
		Consumer: deps.Brokers.TariffConsumer,
		Producer: deps.Brokers.TariffProducer,
	})

	return &Services{
		WalletService:  walletService,
		HistoryService: historyService,
		PaymentCallbackService: callback.NewPaymentCallbackService(callback.PaymentCallbackServiceDeps{
			Logger:            deps.Logger,
			AccountRepository: deps.Repositories.AccountRepository,
			WalletService:     walletService,
			HistoryService:    historyService,
			Notifier: 				 deps.Notifier,
			NotifyChannel: deps.NotificationChannel,
			AdminURL: deps.AdminURL,
		}),
		TariffBrokerService: tariffBrokerService,
	}
}
