//
//  ZJBaseModel.m
//  RealEstateManagement
//
//  Created by Javen on 2017/2/9.
//  Copyright © 2017年 上海勾芒信息科技. All rights reserved.
//

#import "ZJBaseModel.h"

@implementation ZJBaseModel
/**
 字典转模型
 
 @param dic 字典
 @return 转换之后的模型类
 */
+ (instancetype)modelWithDic:(NSDictionary *)dic {
    NSError *error;
    id model = [[self alloc] initWithDictionary:dic error:&error];
    return model;
}

+ (NSMutableArray *)modelsFromArray:(NSArray *)array {
    NSMutableArray *arr = [NSMutableArray array];
    for (NSDictionary *dict in array) {
        id model = [[self class] modelWithDic:dict];
        [arr addObject:model];
    }
    return arr;
}

+ (JSONKeyMapper *)keyMapper {
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{ @"idField" : @"id",
                                                                   @"newField" : @"new" }];
}

/**
 模型转模型
 
 @param model 要转换的模型类
 @return 转换之后的模型类
 */
- (instancetype)modelWithModel:(id)model {
    id destinationModel = [[self class] modelWithDic:[model toDictionary]];
    return destinationModel;
}

- (void)setZj_displayName:(NSString *)zj_displayName {
    _zj_displayName = zj_displayName;
}

- (NSString *)zj_displayName {
    return _zj_displayName;
}


@end
