//
//  MVMCGlobalLoadProtocol.h
//  MVMCore
//
//  Created by Pfeil, Scott Robert on 11/21/17.
//  Copyright © 2017 myverizon. All rights reserved.
//

#import <MVMCore/MVMCoreErrorObject.h>
#import <MVMCore/MVMCoreRequestParameters.h>
#import <MVMCore/MVMCoreViewControllerProtocol.h>
#import <MVMCore/MVMCoreLoadObject.h>
#import <MVMCore/MVMCoreViewManagerProtocol.h>

@protocol  MVMCoreGlobalLoadProtocol <NSObject>

@optional

// Provides the desired error screen for the native error. Called on the main thread. If set, any native errors or NSURLErrorDomain errors will use a native screen.
- (nullable UIViewController <MVMCoreViewControllerProtocol> *)getNativeScreenForRequestError:(nonnull MVMCoreErrorObject *)errorObject requestObject:(nonnull MVMCoreRequestParameters *)requestObject;

/* Can choose to handle global error scenarios here... This will happen for every request so only put things in here that aren't controller specific. Must call completion handler.
 @param completionHandler must be called when finished handling errors. Pass if we should continue or not, and any error object that you want to be handled. */
- (void)handleGlobalErrorsForLoadObject:(nonnull MVMCoreLoadObject *)loadObject completionHandler:(nonnull void (^)(BOOL shouldContinueLoad, MVMCoreErrorObject * _Nullable error))completionHandler;

// Can overwrite this to provide any view controllers that may be cached for the provided load object page type. Allows for using an old screen instead of creating a new screen. This function should not be used to create a screen.
- (nullable UIViewController <MVMCoreViewControllerProtocol>*)getCachedViewControllerForLoadObject:(nonnull MVMCoreLoadObject *)loadObject;

// Can overwrite this function to provide a view manager with the embedded view controller instead of just the view controller. For example, load a custom tab bar with this page as the first tab.
- (nullable UIViewController <MVMCoreViewManagerProtocol,MVMCoreViewControllerProtocol> *)getViewManagerWithViewController:(nonnull UIViewController <MVMCoreViewControllerProtocol> *)viewController loadObject:(nullable MVMCoreLoadObject *)loadObject;

// Can overwrite to set the request time out time.
- (NSTimeInterval)timeOutIntervalForRequest:(nullable MVMCoreRequestParameters *)request;

// Can return an error object.
- (nonnull MVMCoreErrorObject *)createErrorObjectForRequestNSError:(nonnull NSError *)error forRequest:(nonnull NSURLRequest *)request location:(nullable NSString *)locationForError;

@end
