//
//  MainTabBarController.swift
//  MachineLearningDemo
//
//  Created by Pavel Odstrčilík on 20.04.2021.
//

import Foundation
import UIKit
import CoreML

open class MainTabBarController: UITabBarController {

    public init() {
        super.init(nibName: nil, bundle: nil)
        prepareViewControllers()
    }

    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    open func prepareViewControllers() {
        do {
            self.viewControllers = [
                prepareViewController(title: "Correct/Wrong",
                                      model: try CorrectWrong_1(configuration:
                                                                    MLModelConfiguration()).model),
                prepareLabelViewController(title: "Color",
                                           model: try ColorDetection(configuration:
                                                                        MLModelConfiguration()).model)]
        } catch {
            print("Error")
        }
    }

    open func prepareViewController(title: String?, model: MLModel) -> UINavigationController {
        let viewController = BaseViewController(model: model)
        viewController.tabBarItem = prepareTabBarItem(title: title)

        return UINavigationController(rootViewController: viewController)
    }

    open func prepareLabelViewController(title: String?, model: MLModel) -> UINavigationController {
        let viewController = LabelViewController(model: model)
        viewController.tabBarItem = prepareTabBarItem(title: title)

        return UINavigationController(rootViewController: viewController)
    }

    open func prepareTabBarItem(title: String?) -> UITabBarItem {
        let tabBarItem = UITabBarItem()
        tabBarItem.title = title
        tabBarItem.image = UIImage()

        return tabBarItem
    }
}
