package app

import (
	"context"
	"net/http"

	"github.com/AlchemyTelcoSolutions/callisto-so-bff/cmd/app/clients"
	commonDomain "github.com/AlchemyTelcoSolutions/utils/service/domain"
)

// initClients is a function to initialize clients
func (a *App) initClients(ctx context.Context) error {
	// init clients here for the struct
	clientStruct := &Clients{}
	config := a.config.GetConfigurations()

	// Init Callisto API Http Client
	clientStruct.callistoAPIClient = clients.InitCallistoAPIHTTPClient(&http.Client{}, a.logger)

	// Init Callisto so GRPC Client
	if config.CallistoSO.Enabled {
		callistoSO, err := clients.InitCallistoSOGrpcClient(ctx, config.CallistoSO.Host)
		if err != nil {
			return commonDomain.Wrap(err, "error setting up Callisto SO GRPC")
		}
		clientStruct.callistoSOGrpcClient = callistoSO
	}

	a.SetClients(clientStruct)

	return nil
}
