import UIKit

class BalanceRouter {
    weak var viewController: UIViewController?
}

extension BalanceRouter: IBalanceRouter {

    func openReceive(for coin: Coin) {
        DepositRouter.module(coin: coin).show(fromController: viewController)
    }

    func openSend(for coinCode: CoinCode) {
        if let module = SendRouter.module(coinCode: coinCode) {
            module.show(fromController: viewController)
        }
    }

    func openManageCoins() {
        viewController?.present(ManageCoinsRouter.module(), animated: true)
    }

}

extension BalanceRouter {

    static func module() -> UIViewController {
        let router = BalanceRouter()
        let interactor = BalanceInteractor(adapterManager: App.shared.adapterManager, rateStorage: App.shared.grdbStorage, currencyManager: App.shared.currencyManager)
        let presenter = BalancePresenter(interactor: interactor, router: router, dataSource: BalanceItemDataSource(), factory: BalanceViewItemFactory())
        let viewController = BalanceViewController(viewDelegate: presenter)

        interactor.delegate = presenter
        presenter.view = viewController
        router.viewController = viewController

        return viewController
    }

}
