//
//  NSNSDictionary+Convenience.h
//  myverizon
//
//  Created by Scott Pfeil on 11/12/13.
//  Copyright (c) 2013 Verizon Wireless. All rights reserved.
//
//  Adds frequently used convenience methods to NSDictionary.

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface NSDictionary (MFConvenience)

// Gets the object from the dictionary and verfies that it is of a given type.
- (nullable id)objectForKey:(nonnull id<NSCopying>)key ofType:(nonnull Class)type;

// shorthand for objectForKey
- (nullable NSString *)string:(nonnull id<NSCopying>)key;
- (nullable id)dict:(nonnull id<NSCopying>)key;
- (nullable id)array:(nonnull id<NSCopying>)key;
- (BOOL)boolForKey:(nonnull id<NSCopying>)key;
- (NSInteger)integer:(nonnull id<NSCopying>)key;
- (CGFloat)floatForKey:(nonnull id<NSCopying>)key;
- (double)doubleForKey:(nonnull id<NSCopying>)key;
- (nullable NSNumber *)optionalNumberForKey:(nonnull id<NSCopying>)key;

// Not strict, can accept either string or boolean.
- (BOOL)lenientBoolForKey:(nonnull id<NSCopying>)key;

// Gets an object that is nested using a series of keys or indexes to reach it.
// All keys should be of type NSString and is used for nested dictionaries.
// All indexes should be of type NSNumber and is used for nested arrays.
// Root object should be either a NSDictionary or NSArray.
- (nullable id)objectChainOfKeysOrIndexes:(nonnull NSArray *)keysOrIndexes;

// Gets an object that is nested using a series of keys or indexes to reach it and verifies it is of a specific type.
// See objectChainOfKeysOrIndexes
- (nullable id)objectChainOfKeysOrIndexes:(nonnull NSArray *)keysOrIndexes ofType:(nonnull Class)type;

// Returns array or nil
// See objectChainOfKeysOrIndexes
- (nullable NSArray *)arrayForChainOfKeysOrIndexes:(nonnull NSArray *)keysOrIndexes;

// Returns dictionary or nil.
// See objectChainOfKeysOrIndexes
- (nullable NSDictionary *)dictWithChainOfKeysOrIndexes:(nonnull NSArray *)keysOrIndexes;

// Returns a non-nil dictionary, Can be used if trying to add dictionary object to a dictionary or array
// See objectChainOfKeysOrIndexes
- (nonnull NSDictionary *)dictionaryWithChainOfKeysOrIndexes:(nonnull NSArray *)keysOrIndexes;

// Gets string that is nested using a series of keys or indexes to reach it.
// See objectChainOfKeysOrIndexes
- (nonnull NSString *)stringForChainOfKeysOrIndexes:(nonnull NSArray *)keysOrIndexes;

// Gets the string object for a given key. Returns empty string if object for key is not a valid string.
- (nonnull NSString *)stringForKey:(nonnull NSString *)key;

// Gets the dictionary object for a given key. Returns empty dictionary if object for key is not a valid dictionary.
- (nonnull NSDictionary *)dictionaryForKey:(nonnull NSString *)key;

// Gets the array object for a given key. Returns empty array if object for key is not a valid array.
- (nonnull NSArray *)arrayForKey:(nonnull NSString *)key;

// Gets bool that is nested using a series of keys or indexes to reach it.
// See objectChainOfKeysOrIndexes
- (BOOL)boolForChainOfKeysOrIndexes:(nonnull NSArray *)keysOrIndexes;

@end
