//
//  RCTConvert+LSSurvey.m
//  ReactLightspeedSDK
//
//  Created by marc matta on 10/13/16.
//  Copyright © 2016 com.lightspeed. All rights reserved.
//

#import "RCTConvert+LSSurvey.h"
#import <React/RCTUtils.h>

@implementation RCTConvert (LSSurveyAppType)

RCT_ENUM_CONVERTER(LSSurveyAppType, (@{ @"surveyAppTypeMobileAppNA" : @(LSSurveyAppTypeMobile_APP_NA), @"surveyAppTypeMobileAppOnly" : @(LSSurveyAppTypeMobile_APP_ONLY), @"surveyAppTypeMobileAppEnabled" : @(LSSurveyAppTypeMobile_APP_ENABLED)}), LSSurveyAppTypeMobile_APP_NA, integerValue)

@end

@implementation RCTConvert (LSSurvey)

+ (LSSurvey *)LSSurvey:(id)json
{
    NSDictionary *data = [RCTConvert NSDictionary:json];

    if (data.count > 0) {
        LSSurvey *survey = [LSSurvey new];
        
        survey.surveyName = [RCTConvert NSString:RCTNilIfNull(data[@"surveyName"])];
        survey.surveyUrl = [RCTConvert NSString:RCTNilIfNull(data[@"surveyUrl"])];
        survey.resultType = [RCTConvert NSString:RCTNilIfNull(data[@"resultType"])];
        survey.awardMessage = [RCTConvert NSString:RCTNilIfNull(data[@"awardMessage"])];
        survey.screenAwardMessage = [RCTConvert NSString:RCTNilIfNull(data[@"screenAwardMessage"])];

        survey.surveyId = [RCTConvert NSInteger:data[@"surveyId"]];
        survey.surveyLength = [RCTConvert double:data[@"surveyLength"]];
        survey.isSamSample = [RCTConvert BOOL:data[@"isSamSample"]];
        survey.lmQuotaId = [RCTConvert NSInteger:data[@"lmQuotaId"]];
        survey.lmSampleId = [RCTConvert NSInteger:data[@"lmSampleId"]];
        survey.surveyAppType = [RCTConvert LSSurveyAppType:data[@"surveyAppType"]];
        survey.surveyType = [RCTConvert NSString:RCTNilIfNull(data[@"surveyType"])];
        return survey;
    }
    
    return nil;
}
@end
