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

#import "UserInfoReseller.h"
#import "UserInfoOwnerOrg.h"
#import "UserInfoLastModifyInfo.h"
#import "UserInfoCertificate.h"
#import "UserInfoPasswordControl.h"
#import "UserInfoIdCard.h"
#import "UserInfoShop.h"
#import "UserInfoCreateInfo.h"
#import "UserInfoLoginControl.h"


NSString *const kUserInfoResellerBirthday = @"birthday";
NSString *const kUserInfoResellerPortrait = @"portrait";
NSString *const kUserInfoResellerOwnerOrg = @"ownerOrg";
NSString *const kUserInfoResellerCode = @"code";
NSString *const kUserInfoResellerTelephone = @"telephone";
NSString *const kUserInfoResellerMobilephone = @"mobilephone";
NSString *const kUserInfoResellerUuid = @"uuid";
NSString *const kUserInfoResellerLastModifyInfo = @"lastModifyInfo";
NSString *const kUserInfoResellerSocialContact = @"socialContact";
NSString *const kUserInfoResellerCertificate = @"certificate";
NSString *const kUserInfoResellerVersion = @"version";
NSString *const kUserInfoResellerName = @"name";
NSString *const kUserInfoResellerInvitationCode = @"invitationCode";
NSString *const kUserInfoResellerState = @"state";
NSString *const kUserInfoResellerDomain = @"domain";
NSString *const kUserInfoResellerPasswordControl = @"passwordControl";
NSString *const kUserInfoResellerGender = @"gender";
NSString *const kUserInfoResellerReferrer = @"referrer";
NSString *const kUserInfoResellerPostalAddresses = @"postalAddresses";
NSString *const kUserInfoResellerIdCard = @"idCard";
NSString *const kUserInfoResellerShop = @"shop";
NSString *const kUserInfoResellerCreateInfo = @"createInfo";
NSString *const kUserInfoResellerOrder = @"order";
NSString *const kUserInfoResellerLoginControl = @"loginControl";
NSString *const kUserInfoResellerDescription = @"description";


@interface UserInfoReseller ()

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

@end

@implementation UserInfoReseller

@synthesize birthday = _birthday;
@synthesize portrait = _portrait;
@synthesize ownerOrg = _ownerOrg;
@synthesize code = _code;
@synthesize telephone = _telephone;
@synthesize mobilephone = _mobilephone;
@synthesize uuid = _uuid;
@synthesize lastModifyInfo = _lastModifyInfo;
@synthesize socialContact = _socialContact;
@synthesize certificate = _certificate;
@synthesize version = _version;
@synthesize name = _name;
@synthesize invitationCode = _invitationCode;
@synthesize state = _state;
@synthesize domain = _domain;
@synthesize passwordControl = _passwordControl;
@synthesize gender = _gender;
@synthesize referrer = _referrer;
@synthesize postalAddresses = _postalAddresses;
@synthesize idCard = _idCard;
@synthesize shop = _shop;
@synthesize createInfo = _createInfo;
@synthesize order = _order;
@synthesize loginControl = _loginControl;
@synthesize resellerDescription = _resellerDescription;


+ (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.birthday = [self objectOrNilForKey:kUserInfoResellerBirthday fromDictionary:dict];
            self.portrait = [self objectOrNilForKey:kUserInfoResellerPortrait fromDictionary:dict];
            self.ownerOrg = [UserInfoOwnerOrg modelObjectWithDictionary:[dict objectForKey:kUserInfoResellerOwnerOrg]];
            self.code = [self objectOrNilForKey:kUserInfoResellerCode fromDictionary:dict];
            self.telephone = [self objectOrNilForKey:kUserInfoResellerTelephone fromDictionary:dict];
            self.mobilephone = [self objectOrNilForKey:kUserInfoResellerMobilephone fromDictionary:dict];
            self.uuid = [self objectOrNilForKey:kUserInfoResellerUuid fromDictionary:dict];
            self.lastModifyInfo = [UserInfoLastModifyInfo modelObjectWithDictionary:[dict objectForKey:kUserInfoResellerLastModifyInfo]];
            self.socialContact = [self objectOrNilForKey:kUserInfoResellerSocialContact fromDictionary:dict];
            self.certificate = [UserInfoCertificate modelObjectWithDictionary:[dict objectForKey:kUserInfoResellerCertificate]];
            self.version = [[self objectOrNilForKey:kUserInfoResellerVersion fromDictionary:dict] doubleValue];
            self.name = [self objectOrNilForKey:kUserInfoResellerName fromDictionary:dict];
            self.invitationCode = [self objectOrNilForKey:kUserInfoResellerInvitationCode fromDictionary:dict];
            self.state = [self objectOrNilForKey:kUserInfoResellerState fromDictionary:dict];
            self.domain = [self objectOrNilForKey:kUserInfoResellerDomain fromDictionary:dict];
            self.passwordControl = [UserInfoPasswordControl modelObjectWithDictionary:[dict objectForKey:kUserInfoResellerPasswordControl]];
            self.gender = [self objectOrNilForKey:kUserInfoResellerGender fromDictionary:dict];
            self.referrer = [self objectOrNilForKey:kUserInfoResellerReferrer fromDictionary:dict];
            self.postalAddresses = [self objectOrNilForKey:kUserInfoResellerPostalAddresses fromDictionary:dict];
            self.idCard = [UserInfoIdCard modelObjectWithDictionary:[dict objectForKey:kUserInfoResellerIdCard]];
            self.shop = [UserInfoShop modelObjectWithDictionary:[dict objectForKey:kUserInfoResellerShop]];
            self.createInfo = [UserInfoCreateInfo modelObjectWithDictionary:[dict objectForKey:kUserInfoResellerCreateInfo]];
            self.order = [[self objectOrNilForKey:kUserInfoResellerOrder fromDictionary:dict] doubleValue];
            self.loginControl = [UserInfoLoginControl modelObjectWithDictionary:[dict objectForKey:kUserInfoResellerLoginControl]];
            self.resellerDescription = [self objectOrNilForKey:kUserInfoResellerDescription fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.birthday forKey:kUserInfoResellerBirthday];
    [mutableDict setValue:self.portrait forKey:kUserInfoResellerPortrait];
    [mutableDict setValue:[self.ownerOrg dictionaryRepresentation] forKey:kUserInfoResellerOwnerOrg];
    [mutableDict setValue:self.code forKey:kUserInfoResellerCode];
    [mutableDict setValue:self.telephone forKey:kUserInfoResellerTelephone];
    [mutableDict setValue:self.mobilephone forKey:kUserInfoResellerMobilephone];
    [mutableDict setValue:self.uuid forKey:kUserInfoResellerUuid];
    [mutableDict setValue:[self.lastModifyInfo dictionaryRepresentation] forKey:kUserInfoResellerLastModifyInfo];
    [mutableDict setValue:self.socialContact forKey:kUserInfoResellerSocialContact];
    [mutableDict setValue:[self.certificate dictionaryRepresentation] forKey:kUserInfoResellerCertificate];
    [mutableDict setValue:[NSNumber numberWithDouble:self.version] forKey:kUserInfoResellerVersion];
    [mutableDict setValue:self.name forKey:kUserInfoResellerName];
    [mutableDict setValue:self.invitationCode forKey:kUserInfoResellerInvitationCode];
    [mutableDict setValue:self.state forKey:kUserInfoResellerState];
    [mutableDict setValue:self.domain forKey:kUserInfoResellerDomain];
    [mutableDict setValue:[self.passwordControl dictionaryRepresentation] forKey:kUserInfoResellerPasswordControl];
    [mutableDict setValue:self.gender forKey:kUserInfoResellerGender];
    [mutableDict setValue:self.referrer forKey:kUserInfoResellerReferrer];
    [mutableDict setValue:self.postalAddresses forKey:kUserInfoResellerPostalAddresses];
    [mutableDict setValue:[self.idCard dictionaryRepresentation] forKey:kUserInfoResellerIdCard];
    [mutableDict setValue:[self.shop dictionaryRepresentation] forKey:kUserInfoResellerShop];
    [mutableDict setValue:[self.createInfo dictionaryRepresentation] forKey:kUserInfoResellerCreateInfo];
    [mutableDict setValue:[NSNumber numberWithDouble:self.order] forKey:kUserInfoResellerOrder];
    [mutableDict setValue:[self.loginControl dictionaryRepresentation] forKey:kUserInfoResellerLoginControl];
    [mutableDict setValue:self.resellerDescription forKey:kUserInfoResellerDescription];

    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.birthday = [aDecoder decodeObjectForKey:kUserInfoResellerBirthday];
    self.portrait = [aDecoder decodeObjectForKey:kUserInfoResellerPortrait];
    self.ownerOrg = [aDecoder decodeObjectForKey:kUserInfoResellerOwnerOrg];
    self.code = [aDecoder decodeObjectForKey:kUserInfoResellerCode];
    self.telephone = [aDecoder decodeObjectForKey:kUserInfoResellerTelephone];
    self.mobilephone = [aDecoder decodeObjectForKey:kUserInfoResellerMobilephone];
    self.uuid = [aDecoder decodeObjectForKey:kUserInfoResellerUuid];
    self.lastModifyInfo = [aDecoder decodeObjectForKey:kUserInfoResellerLastModifyInfo];
    self.socialContact = [aDecoder decodeObjectForKey:kUserInfoResellerSocialContact];
    self.certificate = [aDecoder decodeObjectForKey:kUserInfoResellerCertificate];
    self.version = [aDecoder decodeDoubleForKey:kUserInfoResellerVersion];
    self.name = [aDecoder decodeObjectForKey:kUserInfoResellerName];
    self.invitationCode = [aDecoder decodeObjectForKey:kUserInfoResellerInvitationCode];
    self.state = [aDecoder decodeObjectForKey:kUserInfoResellerState];
    self.domain = [aDecoder decodeObjectForKey:kUserInfoResellerDomain];
    self.passwordControl = [aDecoder decodeObjectForKey:kUserInfoResellerPasswordControl];
    self.gender = [aDecoder decodeObjectForKey:kUserInfoResellerGender];
    self.referrer = [aDecoder decodeObjectForKey:kUserInfoResellerReferrer];
    self.postalAddresses = [aDecoder decodeObjectForKey:kUserInfoResellerPostalAddresses];
    self.idCard = [aDecoder decodeObjectForKey:kUserInfoResellerIdCard];
    self.shop = [aDecoder decodeObjectForKey:kUserInfoResellerShop];
    self.createInfo = [aDecoder decodeObjectForKey:kUserInfoResellerCreateInfo];
    self.order = [aDecoder decodeDoubleForKey:kUserInfoResellerOrder];
    self.loginControl = [aDecoder decodeObjectForKey:kUserInfoResellerLoginControl];
    self.resellerDescription = [aDecoder decodeObjectForKey:kUserInfoResellerDescription];
    return self;
}

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

    [aCoder encodeObject:_birthday forKey:kUserInfoResellerBirthday];
    [aCoder encodeObject:_portrait forKey:kUserInfoResellerPortrait];
    [aCoder encodeObject:_ownerOrg forKey:kUserInfoResellerOwnerOrg];
    [aCoder encodeObject:_code forKey:kUserInfoResellerCode];
    [aCoder encodeObject:_telephone forKey:kUserInfoResellerTelephone];
    [aCoder encodeObject:_mobilephone forKey:kUserInfoResellerMobilephone];
    [aCoder encodeObject:_uuid forKey:kUserInfoResellerUuid];
    [aCoder encodeObject:_lastModifyInfo forKey:kUserInfoResellerLastModifyInfo];
    [aCoder encodeObject:_socialContact forKey:kUserInfoResellerSocialContact];
    [aCoder encodeObject:_certificate forKey:kUserInfoResellerCertificate];
    [aCoder encodeDouble:_version forKey:kUserInfoResellerVersion];
    [aCoder encodeObject:_name forKey:kUserInfoResellerName];
    [aCoder encodeObject:_invitationCode forKey:kUserInfoResellerInvitationCode];
    [aCoder encodeObject:_state forKey:kUserInfoResellerState];
    [aCoder encodeObject:_domain forKey:kUserInfoResellerDomain];
    [aCoder encodeObject:_passwordControl forKey:kUserInfoResellerPasswordControl];
    [aCoder encodeObject:_gender forKey:kUserInfoResellerGender];
    [aCoder encodeObject:_referrer forKey:kUserInfoResellerReferrer];
    [aCoder encodeObject:_postalAddresses forKey:kUserInfoResellerPostalAddresses];
    [aCoder encodeObject:_idCard forKey:kUserInfoResellerIdCard];
    [aCoder encodeObject:_shop forKey:kUserInfoResellerShop];
    [aCoder encodeObject:_createInfo forKey:kUserInfoResellerCreateInfo];
    [aCoder encodeDouble:_order forKey:kUserInfoResellerOrder];
    [aCoder encodeObject:_loginControl forKey:kUserInfoResellerLoginControl];
    [aCoder encodeObject:_resellerDescription forKey:kUserInfoResellerDescription];
}

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

        copy.birthday = [self.birthday copyWithZone:zone];
        copy.portrait = [self.portrait copyWithZone:zone];
        copy.ownerOrg = [self.ownerOrg copyWithZone:zone];
        copy.code = [self.code copyWithZone:zone];
        copy.telephone = [self.telephone copyWithZone:zone];
        copy.mobilephone = [self.mobilephone copyWithZone:zone];
        copy.uuid = [self.uuid copyWithZone:zone];
        copy.lastModifyInfo = [self.lastModifyInfo copyWithZone:zone];
        copy.socialContact = [self.socialContact copyWithZone:zone];
        copy.certificate = [self.certificate copyWithZone:zone];
        copy.version = self.version;
        copy.name = [self.name copyWithZone:zone];
        copy.invitationCode = [self.invitationCode copyWithZone:zone];
        copy.state = [self.state copyWithZone:zone];
        copy.domain = [self.domain copyWithZone:zone];
        copy.passwordControl = [self.passwordControl copyWithZone:zone];
        copy.gender = [self.gender copyWithZone:zone];
        copy.referrer = [self.referrer copyWithZone:zone];
        copy.postalAddresses = [self.postalAddresses copyWithZone:zone];
        copy.idCard = [self.idCard copyWithZone:zone];
        copy.shop = [self.shop copyWithZone:zone];
        copy.createInfo = [self.createInfo copyWithZone:zone];
        copy.order = self.order;
        copy.loginControl = [self.loginControl copyWithZone:zone];
        copy.resellerDescription = [self.resellerDescription copyWithZone:zone];
    }
    
    return copy;
}


@end
