//
//  JavenSocialContact.m
//
//  Created by Z  on 16/5/11
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "JavenSocialContact.h"


NSString *const kJavenSocialContactEmail = @"email";
NSString *const kJavenSocialContactQq = @"qq";
NSString *const kJavenSocialContactWechat = @"wechat";
NSString *const kJavenSocialContactTencentWeibo = @"tencentWeibo";
NSString *const kJavenSocialContactSinaWeibo = @"sinaWeibo";
NSString *const kJavenSocialContactSkype = @"skype";


@interface JavenSocialContact ()

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

@end

@implementation JavenSocialContact

@synthesize email = _email;
@synthesize qq = _qq;
@synthesize wechat = _wechat;
@synthesize tencentWeibo = _tencentWeibo;
@synthesize sinaWeibo = _sinaWeibo;
@synthesize skype = _skype;


+ (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.email = [self objectOrNilForKey:kJavenSocialContactEmail fromDictionary:dict];
            self.qq = [self objectOrNilForKey:kJavenSocialContactQq fromDictionary:dict];
            self.wechat = [self objectOrNilForKey:kJavenSocialContactWechat fromDictionary:dict];
            self.tencentWeibo = [self objectOrNilForKey:kJavenSocialContactTencentWeibo fromDictionary:dict];
            self.sinaWeibo = [self objectOrNilForKey:kJavenSocialContactSinaWeibo fromDictionary:dict];
            self.skype = [self objectOrNilForKey:kJavenSocialContactSkype fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.email forKey:kJavenSocialContactEmail];
    [mutableDict setValue:self.qq forKey:kJavenSocialContactQq];
    [mutableDict setValue:self.wechat forKey:kJavenSocialContactWechat];
    [mutableDict setValue:self.tencentWeibo forKey:kJavenSocialContactTencentWeibo];
    [mutableDict setValue:self.sinaWeibo forKey:kJavenSocialContactSinaWeibo];
    [mutableDict setValue:self.skype forKey:kJavenSocialContactSkype];

    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.email = [aDecoder decodeObjectForKey:kJavenSocialContactEmail];
    self.qq = [aDecoder decodeObjectForKey:kJavenSocialContactQq];
    self.wechat = [aDecoder decodeObjectForKey:kJavenSocialContactWechat];
    self.tencentWeibo = [aDecoder decodeObjectForKey:kJavenSocialContactTencentWeibo];
    self.sinaWeibo = [aDecoder decodeObjectForKey:kJavenSocialContactSinaWeibo];
    self.skype = [aDecoder decodeObjectForKey:kJavenSocialContactSkype];
    return self;
}

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

    [aCoder encodeObject:_email forKey:kJavenSocialContactEmail];
    [aCoder encodeObject:_qq forKey:kJavenSocialContactQq];
    [aCoder encodeObject:_wechat forKey:kJavenSocialContactWechat];
    [aCoder encodeObject:_tencentWeibo forKey:kJavenSocialContactTencentWeibo];
    [aCoder encodeObject:_sinaWeibo forKey:kJavenSocialContactSinaWeibo];
    [aCoder encodeObject:_skype forKey:kJavenSocialContactSkype];
}

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

        copy.email = [self.email copyWithZone:zone];
        copy.qq = [self.qq copyWithZone:zone];
        copy.wechat = [self.wechat copyWithZone:zone];
        copy.tencentWeibo = [self.tencentWeibo copyWithZone:zone];
        copy.sinaWeibo = [self.sinaWeibo copyWithZone:zone];
        copy.skype = [self.skype copyWithZone:zone];
    }
    
    return copy;
}


@end
