package initialize

import (
	"github.com/gofiber/fiber/v2"
	"go.uber.org/zap"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/interface/client"
	"penahub.gitlab.yandexcloud.net/pena-services/customer/internal/models"
)

type ClientsDeps struct {
	Logger                       *zap.Logger
	AuthURL                      *models.AuthMicroserviceURL
	HubadminURL                  *models.HubadminMicroserviceURL
	CurrencyURL                  *models.CurrencyMicroserviceURL
	DiscountServiceConfiguration *models.DiscountMicroserviceConfiguration
	PaymentServiceConfiguration  *models.PaymentMicroserviceConfiguration
	VerificationURL              *models.VerificationMicroserviceURL
	TemplategenURL               *models.TemplategenMicroserviceURL
	MailClient                   *models.MailConfiguration
	CodewordServiceHost          *models.CodewordMicroserviceConfiguration
}

type Clients struct {
	AuthClient         *client.AuthClient
	HubadminClient     *client.HubadminClient
	CurrencyClient     *client.CurrencyClient
	DiscountClient     *client.DiscountClient
	PaymentClient      *client.PaymentClient
	VerificationClient *client.VerificationClient
	TemplateClient     *client.TemplateClient
	MailClient         *client.MailClient
	CodewordClient     *client.CodewordClient
}

func NewClients(deps ClientsDeps) *Clients {
	return &Clients{
		AuthClient: client.NewAuthClient(client.AuthClientDeps{
			Logger: deps.Logger,
			URLs:   deps.AuthURL,
		}),
		HubadminClient: client.NewHubadminClient(client.HubadminClientDeps{
			Logger: deps.Logger,
			URLs:   deps.HubadminURL,
		}),
		CurrencyClient: client.NewCurrencyClient(client.CurrencyClientDeps{
			Logger: deps.Logger,
			URLs:   deps.CurrencyURL,
		}),
		DiscountClient: client.NewDiscountClient(client.DiscountClientDeps{
			Logger:              deps.Logger,
			DiscountServiceHost: deps.DiscountServiceConfiguration.HostGRPC,
		}),
		PaymentClient: client.NewPaymentClient(client.PaymentClientDeps{
			Logger:             deps.Logger,
			PaymentServiceHost: deps.PaymentServiceConfiguration.HostGRPC,
		}),
		VerificationClient: client.NewVerificationClient(client.VerificationClientDeps{
			Logger: deps.Logger,
			URLs:   deps.VerificationURL,
		}),
		TemplateClient: client.NewTemplateClient(client.TemplateClientDeps{
			Logger: deps.Logger,
			URLs:   deps.TemplategenURL,
		}),
		MailClient: client.NewMailClient(client.MailClientDeps{
			Logger: deps.Logger,
			ApiUrl: deps.MailClient.ApiUrl,
			Sender: deps.MailClient.Sender,
			Auth: &models.PlainAuth{
				Identity: deps.MailClient.Auth.Identity,
				Username: deps.MailClient.Auth.Username,
				Password: deps.MailClient.Auth.Password,
			},
			ApiKey:      deps.MailClient.ApiKey,
			FiberClient: fiber.AcquireClient(),
			MailAddress: deps.MailClient.MailAddress,
		}),
		CodewordClient: client.NewCodewordClient(client.CodewordClientDeps{
			Logger:              deps.Logger,
			CodewordServiceHost: deps.CodewordServiceHost.HostGRPC,
		}),
	}
}
