//
//  LogisticsItemsModel.m
//
//  Created by 杰 张 on 16/8/28
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "LogisticsItemsModel.h"


NSString *const kLogisticsItemsModelOperTime = @"operTime";
NSString *const kLogisticsItemsModelDescription = @"description";
NSString *const kLogisticsItemsModelOperType = @"operType";


@interface LogisticsItemsModel ()

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

@end

@implementation LogisticsItemsModel

@synthesize operTime = _operTime;
@synthesize internalBaseClassDescription = _internalBaseClassDescription;
@synthesize operType = _operType;


+ (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.operTime = [self objectOrNilForKey:kLogisticsItemsModelOperTime fromDictionary:dict];
            self.internalBaseClassDescription = [self objectOrNilForKey:kLogisticsItemsModelDescription fromDictionary:dict];
            self.operType = [self objectOrNilForKey:kLogisticsItemsModelOperType fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.operTime forKey:kLogisticsItemsModelOperTime];
    [mutableDict setValue:self.internalBaseClassDescription forKey:kLogisticsItemsModelDescription];
    [mutableDict setValue:self.operType forKey:kLogisticsItemsModelOperType];

    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.operTime = [aDecoder decodeObjectForKey:kLogisticsItemsModelOperTime];
    self.internalBaseClassDescription = [aDecoder decodeObjectForKey:kLogisticsItemsModelDescription];
    self.operType = [aDecoder decodeObjectForKey:kLogisticsItemsModelOperType];
    return self;
}

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

    [aCoder encodeObject:_operTime forKey:kLogisticsItemsModelOperTime];
    [aCoder encodeObject:_internalBaseClassDescription forKey:kLogisticsItemsModelDescription];
    [aCoder encodeObject:_operType forKey:kLogisticsItemsModelOperType];
}

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

        copy.operTime = [self.operTime copyWithZone:zone];
        copy.internalBaseClassDescription = [self.internalBaseClassDescription copyWithZone:zone];
        copy.operType = [self.operType copyWithZone:zone];
    }
    
    return copy;
}


@end
