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

#import "UserInfoSocialContact.h"


NSString *const kUserInfoSocialContactEmail = @"email";
NSString *const kUserInfoSocialContactQq = @"qq";
NSString *const kUserInfoSocialContactWechat = @"wechat";
NSString *const kUserInfoSocialContactTencentWeibo = @"tencentWeibo";
NSString *const kUserInfoSocialContactSinaWeibo = @"sinaWeibo";
NSString *const kUserInfoSocialContactSkype = @"skype";


@interface UserInfoSocialContact ()

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

@end

@implementation UserInfoSocialContact

@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:kUserInfoSocialContactEmail fromDictionary:dict];
            self.qq = [self objectOrNilForKey:kUserInfoSocialContactQq fromDictionary:dict];
            self.wechat = [self objectOrNilForKey:kUserInfoSocialContactWechat fromDictionary:dict];
            self.tencentWeibo = [self objectOrNilForKey:kUserInfoSocialContactTencentWeibo fromDictionary:dict];
            self.sinaWeibo = [self objectOrNilForKey:kUserInfoSocialContactSinaWeibo fromDictionary:dict];
            self.skype = [self objectOrNilForKey:kUserInfoSocialContactSkype fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.email forKey:kUserInfoSocialContactEmail];
    [mutableDict setValue:self.qq forKey:kUserInfoSocialContactQq];
    [mutableDict setValue:self.wechat forKey:kUserInfoSocialContactWechat];
    [mutableDict setValue:self.tencentWeibo forKey:kUserInfoSocialContactTencentWeibo];
    [mutableDict setValue:self.sinaWeibo forKey:kUserInfoSocialContactSinaWeibo];
    [mutableDict setValue:self.skype forKey:kUserInfoSocialContactSkype];

    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:kUserInfoSocialContactEmail];
    self.qq = [aDecoder decodeObjectForKey:kUserInfoSocialContactQq];
    self.wechat = [aDecoder decodeObjectForKey:kUserInfoSocialContactWechat];
    self.tencentWeibo = [aDecoder decodeObjectForKey:kUserInfoSocialContactTencentWeibo];
    self.sinaWeibo = [aDecoder decodeObjectForKey:kUserInfoSocialContactSinaWeibo];
    self.skype = [aDecoder decodeObjectForKey:kUserInfoSocialContactSkype];
    return self;
}

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

    [aCoder encodeObject:_email forKey:kUserInfoSocialContactEmail];
    [aCoder encodeObject:_qq forKey:kUserInfoSocialContactQq];
    [aCoder encodeObject:_wechat forKey:kUserInfoSocialContactWechat];
    [aCoder encodeObject:_tencentWeibo forKey:kUserInfoSocialContactTencentWeibo];
    [aCoder encodeObject:_sinaWeibo forKey:kUserInfoSocialContactSinaWeibo];
    [aCoder encodeObject:_skype forKey:kUserInfoSocialContactSkype];
}

- (id)copyWithZone:(NSZone *)zone
{
    UserInfoSocialContact *copy = [[UserInfoSocialContact 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
