//
//  DeviceDisabledHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2020/8/12.
//  Copyright © 2020 yin chen. All rights reserved.
//

#import "DeviceDisabledHttpPostCmd+Response.h"
#import "DeviceDisabledHttpPostCmd.h"
#import "DeviceDisabledHttpResult.h"


@protocol DeviceDisabledHttpResultData;
@interface DeviceDisabledHttpResultData : JSONModel
@property NSString<Optional>*code;
@property NSString<Optional>*msg;
@property NSString<Optional>*data;
@end
@implementation DeviceDisabledHttpResultData
@synthesize description;
@end

@interface DeviceDisabledHttpResult()
@property DeviceDisabledHttpResultData *data;
@end

@implementation DeviceDisabledHttpPostCmd (Response)


- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    DeviceDisabledHttpResult *result = [[DeviceDisabledHttpResult alloc]init];
    result = (DeviceDisabledHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[DeviceDisabledHttpResultData 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 DeviceDisabledHttpResult
- (NSMutableArray *)getDeviceDisabledHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    [httpArray addObject:self.data.msg];
    if ([self.data.code isEqualToString:@"200"]) {
        httpArray = [NSMutableArray array];
    }
    return httpArray;
}
@end
