//
//  DeviceInformationHttpCmd+Response.m
//  MobilePortal
//
//  Created by xiejiangbo on 2019/9/4.
//  Copyright © 2019 yin chen. All rights reserved.
//

#import "DeviceInformationHttpCmd+Response.h"
#import "DeviceInformationHttpResult.h"

@protocol DeviceInformationHttpResultData;
@interface DeviceInformationHttpResultData : JSONModel

@property NSString<Optional>*status;
@property NSString<Optional>*responseTime;
@property NSString<Optional>*msg;

@end
@implementation DeviceInformationHttpResultData
@synthesize description;
@end


@protocol DeviceInformationHttpResultData1;
@interface DeviceInformationHttpResultData1 : JSONModel
@property NSMutableArray<Optional,DeviceInformationHttpResultData> *data;
@property NSString<Optional>*msg;
@property NSString<Optional>*success;
@property NSString<Optional>*code;

@end
@implementation DeviceInformationHttpResultData1
@synthesize description;
@end


@interface DeviceInformationHttpResult()
@property DeviceInformationHttpResultData1 *data;
@end

@implementation DeviceInformationHttpCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    DeviceInformationHttpResult *result = [[DeviceInformationHttpResult alloc]init];
    result = (DeviceInformationHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[DeviceInformationHttpResultData1 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 DeviceInformationHttpResult
- (NSMutableArray *)getDeviceInformationHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    [httpArray addObject:[self getNilString:self.data.msg]];
    if ([self.data.msg isEqualToString:@"请求成功"]) {
        httpArray = [NSMutableArray array];
    } else if (!self.data.msg) {
        httpArray = [NSMutableArray array];
//        [httpArray addObject:@"请查看当前网络状态！"];
    }
    return httpArray;
}
@end
