//
//  MVMCoreLoadDelegateProtocol.h
//  myverizon
//
//  Created by Scott Pfeil on 11/26/13.
//  Copyright (c) 2013 Verizon Wireless. All rights reserved.
//
//  The standard post request protocol

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

@protocol MVMCoreLoadDelegateProtocol

@optional

/** Use this function if you want to handle any specific errors in a special manner. You can perform any logic needed here. Default behavior is to present the error.
 *  @param errorObject              The error object
 *  @param loadObject               Contains load data.
 *  @return If we should continue the loading process or end it.
 *  Details: Should handle any view controller specific loading errors. Easy to subclass. Called in checkForErrors */
- (BOOL)checkForDelegateSpecificErrors:(nullable MVMCoreErrorObject *)errorObject loadObject:(nonnull MVMCoreLoadObject *)loadObject completionHandler:(nonnull void (^)(BOOL shouldContinueLoad, MVMCoreLoadObject * _Nullable loadObject, MVMCoreErrorObject * _Nullable error))completionHandler;

/** Notifies the delegate that an error page will be loaded and asks if we should load it.
 *  @param loadObject               Contains load data.
 *  @param error                    Contains any error.
 *  @return TRUE if the calling process should continue. */
- (BOOL)shouldContinueToErrorPage:(nonnull MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error;

/** Notifies the delegate that a module failed to load.
 *  @param module                   The name of the module.
 *  @param loadObject               The load object containing all of the information.
 *  @param error                    The error object passed in will be set in the case of an error.
 *  @return True if the calling process should continue. */
- (BOOL)handleModuleError:(nonnull NSString *)module loadObject:(nonnull MVMCoreLoadObject *)loadObject error:(nonnull MVMCoreErrorObject *)error;

/** Get the alert object whose data will be presented. Overwrite this to alter how you want the alert to show.
 *  @param loadObject               The load object.
 *  @param errorObject              An error object if there was an error.
 *  @return                         Returns the alert object.
 *  Details: Gets the alert that will display to the screen. Easier to subclass here to avoid subclassing the displaying logic. */
- (nullable MVMCoreAlertObject *)alertObjectToShow:(nonnull MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)errorObject;

/** Allows the delegate to handle any field errors.
 *  @param fieldErrors              The field errors.
 *  @param loadObject               The load object.*/
- (void)handleFieldErrors:(nullable NSArray *)fieldErrors loadObject:(nonnull MVMCoreLoadObject *)loadObject;

/** Called when the load is all finished. Use this to perform any cleanup.
 *  @param loadObject               The load object.
 *  @param loadedViewController     If a view controller was loaded or not.
 *  @param error                    The error object.
 *  Details: Only sends an errorObject if there is an error. */
- (void)loadFinished:(nullable MVMCoreLoadObject *)loadObject loadedViewController:(nullable UIViewController <MVMCoreViewControllerProtocol> *)loadedViewController error:(nullable MVMCoreErrorObject *)error;

// Called when the load is cancelled.
- (void)loadCancelled:(nullable MVMCoreLoadObject *)loadObject;

@end

