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

#import "HereSDKDemandPublicTransportRouteLeg+Dictionary.h"
#import "HereSDKDemandLocation+Dictionary.h"
#import "NSString+Utilities.h"
#import "NSDate+NSNumber.h"

@implementation HereSDKDemandPublicTransportRouteLeg (Dictionary)

- (NSString *)tmDescription
{
  switch (self.transportMode)
  {
    case HereSDKDemandPublicTransportRouteLegTransportModeUnknown: return @"UNKNOWN";
    case HereSDKDemandPublicTransportRouteLegTransportModeHighSpeedTrain: return @"HIGH_SPEED_TRAIN";
    case HereSDKDemandPublicTransportRouteLegTransportModeIntercityTrain: return @"INTERCITY_TRAIN";
    case HereSDKDemandPublicTransportRouteLegTransportModeInterRegionalTrain: return @"INTER_REGIONAL_TRAIN";
    case HereSDKDemandPublicTransportRouteLegTransportModeRegionalTrain: return @"REGIONAL_TRAIN";
    case HereSDKDemandPublicTransportRouteLegTransportModeCityTrain: return @"CITY_TRAIN";
    case HereSDKDemandPublicTransportRouteLegTransportModeBus: return @"BUS";
    case HereSDKDemandPublicTransportRouteLegTransportModeFerry: return @"FERRY";
    case HereSDKDemandPublicTransportRouteLegTransportModeSubway: return @"SUBWAY";
    case HereSDKDemandPublicTransportRouteLegTransportModeLightRail: return @"LIGHT_RAIL";
    case HereSDKDemandPublicTransportRouteLegTransportModePrivateBus: return @"PRIVATE_BUS";
    case HereSDKDemandPublicTransportRouteLegTransportModeInclined: return @"INCLINED";
    case HereSDKDemandPublicTransportRouteLegTransportModeAerial: return @"AERIAL";
    case HereSDKDemandPublicTransportRouteLegTransportModeBusRapid: return @"BUS_RAPID";
    case HereSDKDemandPublicTransportRouteLegTransportModeMonorail: return @"MONORAIL";
    case HereSDKDemandPublicTransportRouteLegTransportModeWalk: return @"WALK";
  }
}

- (NSDictionary *)dictionary
{
  NSNumber *estimatedDurationMs = nil;
  if (self.duration)
  {
    double valMs = self.duration.doubleValue * 1000;
    estimatedDurationMs = [NSNumber numberWithDouble:valMs];
  }
    return @{
             @"transportMode": self.tmDescription,
             @"estimatedDurationMs": (estimatedDurationMs) ? estimatedDurationMs : [NSNull null],
             @"length": (self.distance) ? self.distance : [NSNull null],
             @"lineName": [NSString hereSDK_utilities_emptyOrString:self.line],
             @"origin": self.origin.dictionary,
             @"estimatedDepartureTime": (self.departureTime) ? self.departureTime.hereSdk_toNumber : [NSNull null],
             @"destination": self.destination.dictionary,
             @"estimatedArrivalTime": (self.arrivalTime) ? self.arrivalTime.hereSdk_toNumber : [NSNull null],
             @"operatorName": [NSString hereSDK_utilities_emptyOrString:self.transportOperator],
             };
}

@end
