//
//  UserInfoAppConfig.m
//
//  Created by 杰 张 on 16/7/22
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "UserInfoAppConfig.h"


NSString *const kUserInfoAppConfigWebShopBaseUrl = @"webShopBaseUrl";


@interface UserInfoAppConfig ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation UserInfoAppConfig

@synthesize webShopBaseUrl = _webShopBaseUrl;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.webShopBaseUrl = [self objectOrNilForKey:kUserInfoAppConfigWebShopBaseUrl fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.webShopBaseUrl forKey:kUserInfoAppConfigWebShopBaseUrl];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.webShopBaseUrl = [aDecoder decodeObjectForKey:kUserInfoAppConfigWebShopBaseUrl];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_webShopBaseUrl forKey:kUserInfoAppConfigWebShopBaseUrl];
}

- (id)copyWithZone:(NSZone *)zone
{
    UserInfoAppConfig *copy = [[UserInfoAppConfig alloc] init];
    
    if (copy) {

        copy.webShopBaseUrl = [self.webShopBaseUrl copyWithZone:zone];
    }
    
    return copy;
}


@end
