/*
 *    	Copyright 2015-2016 GetSocial B.V.
 *
 *	Licensed under the Apache License, Version 2.0 (the "License");
 *	you may not use this file except in compliance with the License.
 *	You may obtain a copy of the License at
 *
 *    	http://www.apache.org/licenses/LICENSE-2.0
 *
 *	Unless required by applicable law or agreed to in writing, software
 *	distributed under the License is distributed on an "AS IS" BASIS,
 *	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *	See the License for the specific language governing permissions and
 *	limitations under the License.
 */

#import "GetSocialLeaderboardMetaData+Serialize.h"

@implementation GetSocialLeaderboardMetaData (Serialize)

-(NSString*) serialize {
    NSMutableDictionary* dictionary = [[NSMutableDictionary alloc] init];
    [dictionary setObject:[self leaderboardID] forKey:@"leaderboardId"];
    [dictionary setObject:[self name] forKey:@"name"];
    [dictionary setObject:[self unit] forKey:@"units"];
    [dictionary setObject:[NSNumber numberWithInteger:[self direction]] forKey:@"direction"];
    [dictionary setObject:[self format] forKey:@"format"];
    [dictionary setObject:[NSNumber numberWithBool:[self published]] forKey:@"published"];
    NSDictionary* dict = [NSDictionary dictionaryWithDictionary:dictionary];
    
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    
    if (jsonData) {
        return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    } else {
        return @"";
    }
}

@end
