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

#import "UserInfoOwnerOrg.h"


NSString *const kUserInfoOwnerOrgCode = @"code";
NSString *const kUserInfoOwnerOrgName = @"name";
NSString *const kUserInfoOwnerOrgExtra = @"extra";
NSString *const kUserInfoOwnerOrgUuid = @"uuid";


@interface UserInfoOwnerOrg ()

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

@end

@implementation UserInfoOwnerOrg

@synthesize code = _code;
@synthesize name = _name;
@synthesize extra = _extra;
@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.code = [self objectOrNilForKey:kUserInfoOwnerOrgCode fromDictionary:dict];
            self.name = [self objectOrNilForKey:kUserInfoOwnerOrgName fromDictionary:dict];
            self.extra = [self objectOrNilForKey:kUserInfoOwnerOrgExtra fromDictionary:dict];
            self.uuid = [self objectOrNilForKey:kUserInfoOwnerOrgUuid fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.code forKey:kUserInfoOwnerOrgCode];
    [mutableDict setValue:self.name forKey:kUserInfoOwnerOrgName];
    [mutableDict setValue:self.extra forKey:kUserInfoOwnerOrgExtra];
    [mutableDict setValue:self.uuid forKey:kUserInfoOwnerOrgUuid];

    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.code = [aDecoder decodeObjectForKey:kUserInfoOwnerOrgCode];
    self.name = [aDecoder decodeObjectForKey:kUserInfoOwnerOrgName];
    self.extra = [aDecoder decodeObjectForKey:kUserInfoOwnerOrgExtra];
    self.uuid = [aDecoder decodeObjectForKey:kUserInfoOwnerOrgUuid];
    return self;
}

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

    [aCoder encodeObject:_code forKey:kUserInfoOwnerOrgCode];
    [aCoder encodeObject:_name forKey:kUserInfoOwnerOrgName];
    [aCoder encodeObject:_extra forKey:kUserInfoOwnerOrgExtra];
    [aCoder encodeObject:_uuid forKey:kUserInfoOwnerOrgUuid];
}

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

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


@end
