//
//  JavenReseller.m
//
//  Created by Z  on 16/4/25
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "JavenReseller.h"


NSString *const kJavenResellerMobilephone = @"mobilephone";
NSString *const kJavenResellerCode = @"code";
NSString *const kJavenResellerName = @"name";
NSString *const kJavenResellerPortrait = @"portrait";
NSString *const kJavenResellerUuid = @"uuid";


@interface JavenReseller ()

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

@end

@implementation JavenReseller

@synthesize mobilephone = _mobilephone;
@synthesize code = _code;
@synthesize name = _name;
@synthesize portrait = _portrait;
@synthesize uuid = _uuid;


+ (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.mobilephone = [self objectOrNilForKey:kJavenResellerMobilephone fromDictionary:dict];
            self.code = [self objectOrNilForKey:kJavenResellerCode fromDictionary:dict];
            self.name = [self objectOrNilForKey:kJavenResellerName fromDictionary:dict];
            self.portrait = [self objectOrNilForKey:kJavenResellerPortrait fromDictionary:dict];
            self.uuid = [self objectOrNilForKey:kJavenResellerUuid fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.mobilephone forKey:kJavenResellerMobilephone];
    [mutableDict setValue:self.code forKey:kJavenResellerCode];
    [mutableDict setValue:self.name forKey:kJavenResellerName];
    [mutableDict setValue:self.portrait forKey:kJavenResellerPortrait];
    [mutableDict setValue:self.uuid forKey:kJavenResellerUuid];

    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.mobilephone = [aDecoder decodeObjectForKey:kJavenResellerMobilephone];
    self.code = [aDecoder decodeObjectForKey:kJavenResellerCode];
    self.name = [aDecoder decodeObjectForKey:kJavenResellerName];
    self.portrait = [aDecoder decodeObjectForKey:kJavenResellerPortrait];
    self.uuid = [aDecoder decodeObjectForKey:kJavenResellerUuid];
    return self;
}

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

    [aCoder encodeObject:_mobilephone forKey:kJavenResellerMobilephone];
    [aCoder encodeObject:_code forKey:kJavenResellerCode];
    [aCoder encodeObject:_name forKey:kJavenResellerName];
    [aCoder encodeObject:_portrait forKey:kJavenResellerPortrait];
    [aCoder encodeObject:_uuid forKey:kJavenResellerUuid];
}

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

        copy.mobilephone = [self.mobilephone copyWithZone:zone];
        copy.code = [self.code copyWithZone:zone];
        copy.name = [self.name copyWithZone:zone];
        copy.portrait = [self.portrait copyWithZone:zone];
        copy.uuid = [self.uuid copyWithZone:zone];
    }
    
    return copy;
}


@end
