import UIKit

// swiftlint: disable force_cast
enum AppStoryboard: String {
    case main = "Main"
    case voIP = "VoIP"
    case groupChat = "Groupchat"
    case info = "Info"
    case settings = "Settings"
    case account = "Account"

    var instance: UIStoryboard {
        return UIStoryboard(name: self.rawValue, bundle: Bundle.main)
    }

    func instantiateViewController(withIdentifier identifier: String) -> UIViewController {
        return instance.instantiateViewController(withIdentifier: identifier)
    }

    func instantiateViewController<T: UIViewController>(ofClass: T.Type) -> T {
        let storyboardID = ofClass.storyboardID
        return instance.instantiateViewController(withIdentifier: storyboardID) as! T
    }
}

extension UIViewController {
    class var storyboardID: String {
        return "\(self)"
    }

    static func instantiate(fromAppStoryboard: AppStoryboard) -> Self {
        return fromAppStoryboard.instantiateViewController(ofClass: self)
    }
}
