//
//  RCTConvert+LSQuestionAnswer.m
//  ReactLightspeedSDK
//
//  Created by marc matta on 12/21/17.
//  Copyright © 2017 com.lightspeed. All rights reserved.
//

#import "RCTConvert+QuestionAnswer.h"
#import "RCTLSUtils.h"

@implementation RCTConvert (QuestionAnswer)
+ (NSArray *)QuestionAnswerArray:(id)json {
    NSArray *data = [RCTConvert NSArray:json];
    NSMutableArray *array = [NSMutableArray array];
    
    for (id json in data) {
        [array addObject:[RCTConvert QuestionAnswer:json]];
    }
    
    return array;
}

+ (QuestionAnswer *)QuestionAnswer:(id)json
{
    NSDictionary *data = [RCTConvert NSDictionary:json];
    
    if (data.count > 0) {
        NSInteger questionId = [RCTConvert NSInteger:data[@"questionId"]];
        NSArray* answers = [RCTConvert NSStringArray:RCTNilIfNull(data[@"answers"])] ? : @[];
        QuestionAnswer *answer = [[QuestionAnswer alloc] initWithQuestionId:questionId answers:answers];
        return answer;
    }
    
    return nil;
}
@end
