//
//  UntuedCellPhoneHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by xiejiangbo on 2019/7/1.
//  Copyright © 2019 yin chen. All rights reserved.
//

#import "UntuedCellPhoneHttpPostCmd+Response.h"
#import "UntuedCellPhoneHttpPostResult.h"

@protocol UntuedCellPhoneHttpPostResultDataList;
@interface UntuedCellPhoneHttpPostResultDataList : JSONModel
@property NSString<Optional>*user_id;
@property NSString<Optional>*device_name;
@property NSString<Optional>*status;
@property NSString<Optional>*device_userid;
@property NSString<Optional>*device_changeid;
@property NSString<Optional>*device_sid;
@property NSString<Optional>*username;
@property NSString<Optional>*device_type;
@property NSString<Optional>*id;
@end
@implementation UntuedCellPhoneHttpPostResultDataList
@synthesize description;
@end


@protocol UntuedCellPhoneHttpPostResultData;
@interface UntuedCellPhoneHttpPostResultData : JSONModel

@property NSMutableArray<Optional,UntuedCellPhoneHttpPostResultDataList>*list;
@end
@implementation UntuedCellPhoneHttpPostResultData
@synthesize description;
@end


@interface UntuedCellPhoneHttpPostResult()
@property UntuedCellPhoneHttpPostResultData *data;
@end


@implementation UntuedCellPhoneHttpPostCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    UntuedCellPhoneHttpPostResult *result = [[UntuedCellPhoneHttpPostResult alloc]init];
    result = (UntuedCellPhoneHttpPostResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[UntuedCellPhoneHttpPostResultData alloc]initWithDictionary:dic error:(NSError **)&error];
        if(error){
            [self onRequestFailed:error];
            return;
        }
    }else{
        NSString *memo = [dic objectForKey:@"error_description"];
        [self.result setResultState:kRequestResultFail];
        [self.result setErrMsg:memo];
        NSLog(@"code :%ld errormsg:%@",(long)code,memo);
    }
}
- (void)onRequestFailed:(NSError *)error{
    NSLog(@"Error===%@",error);
    [self.result setErrMsg:[error localizedDescription]];
    [self.result setResultState:kRequestResultFail];
}
@end
@implementation UntuedCellPhoneHttpPostResult
- (NSMutableArray *)getUntuedCellPhoneHttpPostResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    for (int index = 0; index<self.data.list.count; index ++) {
        UntuedCellPhoneHttpPostResultDataList *httpModel = self.data.list[index];
        UntuedCellPhoneHttpPostListModel *model = [[UntuedCellPhoneHttpPostListModel alloc]init];
        model.status = [self getNilString:httpModel.status];
        model.user_id = [self getNilString:httpModel.user_id];
        model.device_sid = [self getNilString:httpModel.device_sid];
        model.device_name = [self getNilString:httpModel.device_name];
        model.id = [self getNilString:httpModel.id];
        model.device_userid = [self getNilString:httpModel.device_userid];
        model.device_type = [self getNilString:httpModel.device_type];
        model.username = [self getNilString:httpModel.username];
        model.device_changeid = [self getNilString:httpModel.device_changeid];
        [httpArray addObject:model];
    }
    return httpArray;
}
@end
