//
//  MVMCoreAlertObject.h
//  myverizon
//
//  Created by Scott Pfeil on 11/21/14.
//  Copyright (c) 2014 Verizon Wireless. All rights reserved.
//
//  An object for keeping track of all alert variables. Easier to pass around.

#import <Foundation/Foundation.h>
#import <MVMCore/MVMCoreActionDelegateProtocol.h>
#import <MVMCore/MVMCoreLoadDelegateProtocol.h>
#import <MVMCore/MVMCorePresentationDelegateProtocol.h>
#import <MVMCore/MVMCoreAlertDelegateProtocol.h>

@class MVMCoreErrorObject;
@class MVMCoreLoadObject;
@class DelegateObject;

typedef NS_ENUM(NSInteger, MFAlertType) {
    MFAlertTypePopup = 0,
    MFAlertTypeField,
    MFAlertTypeTop,
    MFAlertTypeNone
};

typedef void (^TextFieldErrorHandler)(NSArray * _Nonnull fieldErrors);

@interface MVMCoreAlertObject : NSObject

@property (nullable, strong, nonatomic) NSString *title;
@property (nullable, copy, nonatomic) NSDictionary *pageJson;
@property (nullable, strong, nonatomic) NSString *message;
@property (nonnull, strong, nonatomic) NSArray *actions;
@property (nonatomic) BOOL isGreedy;
@property (nonatomic) UIAlertControllerStyle alertStyle;
@property (nonatomic) MFAlertType type;
@property (nonatomic) BOOL defaultAction;

@property (nonnull, strong, nonatomic) NSArray *fieldErrors;
@property (nullable, nonatomic, copy) TextFieldErrorHandler textFieldErrorHandler;

// Set to be notified of popup style alert events.
@property (nonatomic, weak, nullable) NSObject <MVMCoreAlertDelegateProtocol> *alertDelegate;

// Creates an alert object for an error with the passed in load object response info
+ (nullable instancetype)alertObjectForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error delegateObject:(nullable DelegateObject *)delegateObject;
+ (nullable instancetype)alertObjectForPageType:(nullable NSString *)pageType responseInfo:(nullable NSDictionary *)responseInfo additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject;

// Initializes a popup style alert object. Look at the alert handler to see what each is used for.
- (nullable instancetype)initPopupAlertWithTitle:(nullable NSString *)title message:(nullable NSString *)message actions:(nonnull NSArray *)actions isGreedy:(BOOL)isGreedy;

// Initializes a popup style alert object using the error passed in. Message is formatted default style. By defualt uses the Okay button to just dismiss the error.
- (nullable instancetype)initPopupAlertWithError:(nullable MVMCoreErrorObject *)error isGreedy:(BOOL)isGreedy;

// Same as above but no default actions. They are passed in.
- (nullable instancetype)initPopupAlertWithError:(nullable MVMCoreErrorObject *)error actions:(nonnull NSArray *)actions isGreedy:(BOOL)isGreedy;

// Returns the alert object made with the page json. If there is not enough data to make, we will set error
+ (nullable instancetype)alertObjectWithPage:(nullable NSDictionary *)page isGreedy:(BOOL)isGreedy additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject error:(MVMCoreErrorObject *_Nullable *_Nullable)error;

// Will show this alert in it's appropriate type style.
- (void)showAlert;

#pragma mark - Deprecated

// Creates an alert object for an error with the passed in load object response info
+ (nullable instancetype)alertObjectForLoadObject:(nullable MVMCoreLoadObject *)loadObject error:(nullable MVMCoreErrorObject *)error actionDelegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)actionDelegate __deprecated;
+ (nullable instancetype)alertObjectForPageType:(nullable NSString *)pageType responseInfo:(nullable NSDictionary *)responseInfo additionalData:(nullable NSDictionary *)additionalData actionDelegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)actionDelegate __deprecated;
+ (nullable instancetype)alertObjectWithPage:(nullable NSDictionary *)page isGreedy:(BOOL)isGreedy additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol,MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate error:(MVMCoreErrorObject *_Nullable *_Nullable)error __deprecated;

@end
