//
// GetETicketsResponseJsonMapper.m
// LiveProject
//
// Created by Ziv on 15/9/21.
//
//

#import "GetETicketsResponseJsonMapper.h"
#import "BeanUtils.h"
#import "CocoaUtils.h"
#import "Utility.h"
#import <BlocksKit/BlocksKit.h>
#import <RestKit/RKObjectMappingOperationDataSource.h>

@implementation GetETicketsResponseJsonMapper

- (instancetype)init {
	if (self = [super init]) {
		RKObjectMapping *eTicketMapping = [RKObjectMapping mappingForClass:[_ETicket class]];
		[eTicketMapping addAttributeMappingsFromArray:[BeanUtils keysForAccessibleSimplePropertyWithClass:[_ETicket class]]];

		RKObjectMapping *getETicketMapping = [RKObjectMapping mappingForClass:[GetETicketsResponse class]];
		[getETicketMapping addAttributeMappingsFromArray:[BeanUtils keysForAccessibleSimplePropertyWithClass:[GetETicketsResponse class]]];
		[getETicketMapping addRelationshipMappingWithSourceKeyPath:@"order_summary" mapping:eTicketMapping];
		[getETicketMapping addRelationshipMappingWithSourceKeyPath:@"etickets" mapping:eTicketMapping];

		self.objectMapping = getETicketMapping;
	}
	return self;
}

#pragma mark - Public

- (NSError *)parseWithJSONObject:(id)jsonObject {
	self.response = [[GetETicketsResponse alloc] init];

	RKMappingOperation *mappingOperation = [[RKMappingOperation alloc] initWithSourceObject:jsonObject destinationObject:self.response mapping:self.objectMapping];
	RKObjectMappingOperationDataSource *mappingOperationDataSource = [[RKObjectMappingOperationDataSource alloc] init];
	mappingOperation.dataSource = mappingOperationDataSource;

	NSError *error = nil;
	[mappingOperation performMapping:&error];
	return error;
}

@end
