//
//  DOHTTPMantleJSONFilter.h
//  DOCore
//
//  Created by Ben Dolman on 3/5/15.
//
//

#import <Foundation/Foundation.h>
#import <DOCore/DOHTTPResponseFilter.h>

extern NSString * const DOHTTPMantleJSONFilterErrorDomain;
enum {
    DOHTTPMantleJSONFilterInvalidObject = 1,
};

/**
 * A filter to convert a JSON object to a Mantle class or collection of classes.
 * The input to this filter must be an NSDictionary or NSArray, depending on how
 * it is initialized.
 */
@interface DOHTTPMantleJSONFilter : NSObject <DOHTTPResponseFilter>

/**
 * Initializes the filter with a single class. This class must be a subclass of MTLModel
 * and conform to MTLJSONSerializing. The return object will be an instance of this class.
 * The filter input object must be an NSDictionary.
 */
- (instancetype)initWithClass:(Class)mantleClass;

/**
 * Initializes the filter with a mapping of keypaths to Mantle classes. When the filter runs
 * it will look up each keypath in the input dictionary and convert its value to the Mantle class
 * in the map. This is so you can map an object like this:
 *
 *     { user: {name:'Josie'}, token: 'ABCDEFG' } ---> { user: [DOUser class], token: 'ABCDEFG' }
 *
 * The values in the mapping dictionary must be subclasses of MTLModel and conform to MTLJSONSerializing.
 *
 * The filter input object must be an NSDictionary.
 */
- (instancetype)initForDictionaryWithKeyPathClasses:(NSDictionary *)keyPathMap;

/**
 * Initializes the filter with a single class. This class must be a subclass of MTLModel
 * and conform to MTLJSONSerializing. The return object will be an array containing objects of this class.
 * The filter input object must be an NSArray
 */
- (instancetype)initForArrayOfClass:(Class)mantleClass;

@end
