//
//  LSDeviceService+RCTNativeModel.m
//  ReactLightspeedSDK
//
//  Created by marc matta on 11/25/16.
//  Copyright © 2016 com.lightspeed. All rights reserved.
//

#import "LSDeviceService+RCTNativeModel.h"
#import <React/RCTUtils.h>

@implementation LSDeviceService (RCTNativeModel)

- (NSDictionary *)reactNativeRepresentation {
    return @{
             @"name":RCTNullIfNil(self.name),
             @"state":@(RCTZeroIfNaN(self.state))
             };
}

@end

@implementation RCTConvert (LSDeviceService)

+ (LSDeviceService *)LSDeviceService:(id)json
{
    NSDictionary *data = [RCTConvert NSDictionary:json];
    if (data.count > 0) {
        LSDeviceService *service = [[LSDeviceService alloc] initWithRepresentation:@{@"deviceServiceName":data[@"name"], @"deviceServiceState": @([data[@"state"] integerValue]) }];
        return service;
    }
    return nil;
}

+ (NSArray<LSDeviceService *> *)LSDeviceServiceArray:(id)json {
    NSArray *data = [RCTConvert NSArray:json];
    if (data.count > 0) {
        NSMutableArray *services = [NSMutableArray array];
        for (id serviceJSON in data) {
            [services addObject:[RCTConvert LSDeviceService:serviceJSON]];
        }
        
        return services;
    }
    return nil;
}

@end
