package initialize

import (
	"github.com/themakers/hlog"
	"go.uber.org/zap"
	qutils "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/broker/tariff"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/grpc/customer"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/grpc/payment"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http/account_admin"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http/account_client"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http/cart_client"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http/currency_admin"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http/currency_client"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http/history_admin"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http/history_client"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/controller/http/wallet_client"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
)

type RpcControllersDeps struct {
	Logger       *zap.Logger
	Services     *Services
	Repositories *Repositories
	HLogger      hlog.Logger
}

type RpcControllers struct {
	PaymentController  *payment.Controller
	CustomerController *customer.Controller
}

func NewRpcControllers(deps RpcControllersDeps) *RpcControllers {
	return &RpcControllers{
		PaymentController: payment.New(payment.Deps{
			Logger:                 deps.Logger,
			PaymentCallbackService: deps.Services.PaymentCallbackService,
			HLogger:                deps.HLogger,
		}),
		CustomerController: customer.New(customer.Deps{
			Logger:         deps.Logger,
			HistoryService: deps.Services.HistoryService,
			AccountRepo:    deps.Repositories.AccountRepository,
		}),
	}
}

type HttpControllersDeps struct {
	Encrypt      *qutils.Encrypt
	Producer     *tariff.Producer
	GRPC         *models.ConfigurationGRPC
	MiddleWare   *http.MiddleWare
	Logger       *zap.Logger
	Repositories *Repositories
	Clients      *Clients
}

type HttpController struct {
	AccountClientController  *account_client.AccountController
	AccountAdminController   *account_admin.AccountInternalController
	CartClientController     *cart_client.CartController
	CurrencyClientController *currency_client.CurrencyController
	CurrencyAdminController  *currency_admin.CurrencyController
	HistoryAdminController   *history_admin.HistoryController
	HistoryClientController  *history_client.HistoryController
	WalletClientController   *wallet_client.WalletController
}

func NewHttpControllers(deps HttpControllersDeps) *HttpController {
	return &HttpController{
		AccountClientController: account_client.NewAccountController(account_client.Deps{
			MiddleWare:  deps.MiddleWare,
			AccountRepo: deps.Repositories.AccountRepository,
			Logger:      deps.Logger,
			Encrypt:     deps.Encrypt,
			AuthClient:  deps.Clients.AuthClient,
		}),
		AccountAdminController: account_admin.NewAccountInternalController(
			account_admin.Deps{
				MiddleWare:  deps.MiddleWare,
				AccountRepo: deps.Repositories.AccountRepository,
				Logger:      deps.Logger,
			}),
		CartClientController: cart_client.NewCartController(cart_client.Deps{
			MiddleWare:     deps.MiddleWare,
			Logger:         deps.Logger,
			AccountRepo:    deps.Repositories.AccountRepository,
			HistoryRepo:    deps.Repositories.HistoryRepository,
			HubAdminClient: deps.Clients.HubadminClient,
			DiscountClient: deps.Clients.DiscountClient,
			CurrencyClient: deps.Clients.CurrencyClient,
			Producer:       deps.Producer,
		}),
		CurrencyClientController: currency_client.NewCurrencyController(currency_client.Deps{
			CurrencyRepo: deps.Repositories.CurrencyRepository,
			MiddleWare:   deps.MiddleWare,
			Logger:       deps.Logger,
		}),
		CurrencyAdminController: currency_admin.NewCurrencyController(currency_admin.Deps{
			CurrencyRepo: deps.Repositories.CurrencyRepository,
			MiddleWare:   deps.MiddleWare,
			Logger:       deps.Logger,
		}),
		HistoryAdminController: history_admin.NewHistoryController(history_admin.Deps{
			MiddleWare:     deps.MiddleWare,
			HistoryRepo:    deps.Repositories.HistoryRepository,
			AccountRepo:    deps.Repositories.AccountRepository,
			VerifyClient:   deps.Clients.VerificationClient,
			AuthClient:     deps.Clients.AuthClient,
			TemplateClient: deps.Clients.TemplateClient,
			CodewordClient: deps.Clients.CodewordClient,
			Logger:         deps.Logger,
		}),
		HistoryClientController: history_client.NewHistoryController(history_client.Deps{
			MiddleWare:     deps.MiddleWare,
			HistoryRepo:    deps.Repositories.HistoryRepository,
			AccountRepo:    deps.Repositories.AccountRepository,
			VerifyClient:   deps.Clients.VerificationClient,
			AuthClient:     deps.Clients.AuthClient,
			TemplateClient: deps.Clients.TemplateClient,
			CodewordClient: deps.Clients.CodewordClient,
			Logger:         deps.Logger,
		}),
		WalletClientController: wallet_client.NewWalletController(wallet_client.Deps{
			MiddleWare:     deps.MiddleWare,
			AuthClient:     deps.Clients.AuthClient,
			PaymentClient:  deps.Clients.PaymentClient,
			GRPC:           deps.GRPC,
			AccountRepo:    deps.Repositories.AccountRepository,
			CurrencyClient: deps.Clients.CurrencyClient,
			VerifyClient:   deps.Clients.VerificationClient,
			MailClient:     deps.Clients.MailClient,
			Logger:         deps.Logger,
		}),
	}
}
