/***************************************************************
 * Copyright © 2017 HERE Global B.V. All rights reserved. *
 **************************************************************/

#import "HereSDKDemandLocation+JSDictionary.h"
#import "HereSDKAddressData+JSDictionary.h"

@implementation HereSDKDemandLocation (JSDictionary)

+ (HereSDKDemandLocation *)locationFromJSParams:(NSDictionary *)params
{
    CLLocation *location = [[CLLocation alloc] initWithLatitude: [params[@"location"][@"lat"] doubleValue] longitude: [params[@"location"][@"lng"] doubleValue]];
    HereSDKAddressData *addressData = nil;

    NSDictionary *addressDataDict = params[@"address"];
    if (addressDataDict)
    {
        addressData = [HereSDKAddressData requestFromJSParams:addressDataDict];
    }
    return [[HereSDKDemandLocation alloc] initWithLocation:location address:addressData freeText:params[@"description"]];
}

@end
