//
//  HomeRouter.swift
//  xDrip
//
//  Created by Artem Kalmykov on 11.03.2020.
//  Copyright (c) 2020 Faifly. All rights reserved.
//
//  This file was generated by the Clean Swift Xcode Templates so
//  you can apply clean architecture to your iOS and Mac projects,
//  see http://clean-swift.com
//

import UIKit

@objc protocol HomeRoutingLogic {
    func routeToCarbsEntriesList()
    func routeToBolusEntriesList()
}

protocol HomeDataPassing {
    var dataStore: HomeDataStore? { get }
}

final class HomeRouter: NSObject, HomeRoutingLogic, HomeDataPassing {
    weak var viewController: HomeViewController?
    var dataStore: HomeDataStore?
    
    // MARK: Routing
    
    func routeToBolusEntriesList() {
        routeToEntriesList(for: .bolus)
    }
    
    func routeToCarbsEntriesList() {
        routeToEntriesList(for: .carbs)
    }
    
    private func routeToEntriesList(for type: Root.EntryType) {
        guard let controller = UIStoryboard(board: .entries).instantiateViewController(withIdentifier: EntriesListRouter.entriesListNavigationControllerIdentifier) as? UINavigationController,
            let entriesListViewController = controller.topViewController as? EntriesListViewController
            else { return }
        
        let builder = EntriesListSceneBuilder()
        
        switch type {
        case .carbs:
            builder.configureSceneForCarbs(entriesListViewController)
        case .bolus:
            builder.configureSceneForBolus(entriesListViewController)
        default:
            break
        }
        
        viewController?.present(controller, animated: true)
    }
}
