package swagger

import (
	"log"

	"github.com/labstack/echo/v4"
)

type accountController interface {
	RemoveAccount(ctx echo.Context) error
	GetAccount(ctx echo.Context) error
	CreateAccount(ctx echo.Context) error
	RemoveDirectAccount(ctx echo.Context, userID string) error
	GetDirectAccount(ctx echo.Context, userID string) error
	GetAccounts(echo.Context, PaginationAccountsParams) error
	SetVerificationStatus(ctx echo.Context, userID string) error
	UpdateAccountName(ctx echo.Context) error
}

type currencyController interface {
	GetCurrencies(ctx echo.Context) error
	PutCurrencies(ctx echo.Context) error
}

type cartController interface {
	Remove(echo.Context, RemoveFromCartParams) error
	Add(echo.Context, Add2cartParams) error
	Pay(echo.Context) error
}

type walletController interface {
	ChangeCurrency(ctx echo.Context) error
	GetPaymentLink(ctx echo.Context) error
}

type historyController interface {
	GetHistoryList(ctx echo.Context, params GetHistoryParams) error
	GetRecentTariffs(ctx echo.Context) error
	SendReport(ctx echo.Context) error
	CalculateLTV(ctx echo.Context) error
}

type Deps struct {
	AccountController  accountController
	CurrencyController currencyController
	CartController     cartController
	WalletController   walletController
	HistoryController  historyController
}

type API struct {
	accountController  accountController
	currencyController currencyController
	cartController     cartController
	walletController   walletController
	historyController  historyController
}

func New(deps Deps) *API {
	if deps.AccountController == nil {
		log.Panicln("AccountController is nil on <New (API)>")
	}

	if deps.CurrencyController == nil {
		log.Panicln("currencyController is nil on <New (API)>")
	}

	if deps.CartController == nil {
		log.Panicln("cartController is nil on <New (API)>")
	}

	if deps.WalletController == nil {
		log.Panicln("walletController is nil on <New (API)>")
	}

	if deps.HistoryController == nil {
		log.Panicln("historyController is nil on <New (API)>")
	}

	return &API{
		accountController:  deps.AccountController,
		currencyController: deps.CurrencyController,
		cartController:     deps.CartController,
		walletController:   deps.WalletController,
		historyController:  deps.HistoryController,
	}
}

// Account

func (receiver *API) DeleteAccount(ctx echo.Context) error {
	return receiver.accountController.RemoveAccount(ctx)
}

func (receiver *API) ChangeAccount(ctx echo.Context) error {
	return receiver.accountController.UpdateAccountName(ctx)
}

func (receiver *API) SetAccountVerificationStatus(ctx echo.Context, userID string) error {
	return receiver.accountController.SetVerificationStatus(ctx, userID)
}

func (receiver *API) GetAccount(ctx echo.Context) error {
	return receiver.accountController.GetAccount(ctx)
}

func (receiver *API) AddAccount(ctx echo.Context) error {
	return receiver.accountController.CreateAccount(ctx)
}

func (receiver *API) DeleteDirectAccount(ctx echo.Context, userID string) error {
	return receiver.accountController.RemoveDirectAccount(ctx, userID)
}

func (receiver *API) GetDirectAccount(ctx echo.Context, userID string) error {
	return receiver.accountController.GetDirectAccount(ctx, userID)
}

func (receiver *API) PaginationAccounts(ctx echo.Context, params PaginationAccountsParams) error {
	return receiver.accountController.GetAccounts(ctx, params)
}

// Cart

func (receiver *API) RemoveFromCart(ctx echo.Context, params RemoveFromCartParams) error {
	return receiver.cartController.Remove(ctx, params)
}

func (receiver *API) Add2cart(ctx echo.Context, params Add2cartParams) error {
	return receiver.cartController.Add(ctx, params)
}

func (receiver *API) PayCart(ctx echo.Context) error {
	return receiver.cartController.Pay(ctx)
}

// Currency

func (receiver *API) GetCurrencies(ctx echo.Context) error {
	return receiver.currencyController.GetCurrencies(ctx)
}

func (receiver *API) UpdateCurrencies(ctx echo.Context) error {
	return receiver.currencyController.PutCurrencies(ctx)
}

// History

func (receiver *API) GetHistory(ctx echo.Context, params GetHistoryParams) error {
	return receiver.historyController.GetHistoryList(ctx, params)
}

func (receiver *API) GetRecentTariffs(ctx echo.Context) error {
	return receiver.historyController.GetRecentTariffs(ctx)
}

func (receiver *API) SendReport(ctx echo.Context) error {
	return receiver.historyController.SendReport(ctx)
}

func (receiver *API) CalculateLTV(ctx echo.Context) error {
	return receiver.historyController.CalculateLTV(ctx)
}

// Wallet

func (receiver *API) RequestMoney(ctx echo.Context) error {
	return receiver.walletController.GetPaymentLink(ctx)
}

func (receiver *API) ChangeCurrency(ctx echo.Context) error {
	return receiver.walletController.ChangeCurrency(ctx)
}
