//
//  MVMCoreViewControllerMappingObject.h
//  myverizon
//
//  Created by Scott Pfeil on 12/2/13.
//  Copyright (c) 2013 Verizon Wireless. All rights reserved.
//
//  Singleton for using template id string to create view controllers based on mapping objects. Any given templateID will map to a view controller.

#import <Foundation/Foundation.h>
#import <MVMCore/MVMCoreViewControllerProtocol.h>
@class MVMCoreErrorObject;

// Classes that use the protocol should be able to be added to the mapping and create a view controller when called upon.
@protocol MVMCoreViewControllerMappingProtocol <NSObject>

// Creates and returns an mvm view controller.
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createViewController;

@end

@interface MVMCoreViewControllerMappingObject : NSObject

// The template based mapping.
@property (nullable, strong, nonatomic) NSMutableDictionary <NSString *,NSObject <MVMCoreViewControllerMappingProtocol>*> *viewControllerMapping;

// The modules that the page can't survive without. Will throw an error if not all are found during loading.
@property (nullable, strong, nonatomic) NSMutableDictionary *requiredModuleMapping;

// The modules that the page will ask for but may not get.
@property (nullable, strong, nonatomic) NSMutableDictionary *optionalModuleMapping;

// Legacy: page type based mapping
@property (nullable, strong, nonatomic) NSMutableDictionary <NSString *,NSObject <MVMCoreViewControllerMappingProtocol>*> *pageTypeViewControllerMapping;

// Returns the shared instance
+ (nullable instancetype)sharedViewControllerMappingObject;

#pragma mark - View Controller Mapping

// Returns the mapping object which maps the given template to how it's view controller is loaded.
- (nullable NSObject <MVMCoreViewControllerMappingProtocol>*)getViewControllerMappingForTemplate:(nonnull NSString *)templateID;

// Creates and returns an mvm view controller of the passed in template or page type using the mapping.
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createMFViewControllerOfTemplate:(nonnull NSString *)templateID;

// For pages external to the mobile first framework to be added to the view controller mapping.
- (void)addToTemplateViewControllerMapping:(nullable NSDictionary <NSString *,NSObject <MVMCoreViewControllerMappingProtocol>*>*)map;

// Transition function: A mix of new and legacy.
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createMFViewControllerOfTemplate:(nullable NSString *)templateID pageType:(nullable NSString *)pageType;

#pragma mark - Module PageType Mapping

// Returns the required modules for a given page.
- (nullable NSArray *)modulesRequiredForPageType:(nonnull NSString *)pageType;

// For pages external to the mobile first framework to add their required modules.
- (void)addRequiredModulesToMapping:(nonnull NSArray *)mapping forPageType:(nonnull NSString *)pageType;

// Returns the optional modules for a given page
- (nullable NSArray *)modulesOptionalForPageType:(nonnull NSString *)pageType;

// For pages external to the mobile first framework to add their optional modules.
- (void)addOptionalModulesToMapping:(nonnull NSArray *)mapping forPageType:(nonnull NSString *)pageType;

// Returns all the modules needed for a given page type.
- (nullable NSArray *)allModulesForPageType:(nonnull NSString *)pageType;

// Add optional modules for multiple pages. Used by external frameworks
- (void)addOptionalModulesForPages:(nonnull NSDictionary<NSString*, NSArray<NSString*>*>*)optionalModulesForPages;

#pragma mark - Legacy PageType driven

// Returns the mapping object which maps the given page type to how it's view controller is loaded.
- (nullable NSObject <MVMCoreViewControllerMappingProtocol>*)getViewControllerMappingForPageType:(nonnull NSString *)pageType;

// For pages external to the mobile first framework to be added to the view controller mapping for pagetypes.
- (void)addToPageTypeViewControllerMapping:(nullable NSDictionary <NSString *,NSObject <MVMCoreViewControllerMappingProtocol>*>*)map;

// Creates and returns an mvm view controller of the passed in template or page type using the mapping.
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)createMFViewControllerOfPageType:(nonnull NSString *)pageType;

@end
