//
//  ScopeListHttpCmd+Response.m
//  MobilePortal
//
//  Created by xiejiangbo on 2019/11/18.
//  Copyright © 2019 yin chen. All rights reserved.
//

#import "ScopeListHttpCmd+Response.h"
#import "ScopeListHttpCmd.h"
#import "ScopeListHttpResult.h"


@protocol ScopeListHttpResultDataData;
@interface ScopeListHttpResultDataData : JSONModel
@property NSString<Optional>*system;
@property NSString<Optional>*content;
@property NSString<Optional>*sort;
@property NSString<Optional>*id;
@property NSString<Optional>*createby;
@property NSString<Optional>*updateon;
@property NSString<Optional>*keyword;
@property NSString<Optional>*state;
@property NSString<Optional>*updateby;
@property NSString<Optional>*name;
@property NSString<Optional>*createon;
@property NSString<Optional>*type;
@end
@implementation ScopeListHttpResultDataData
@synthesize description;
@end


@protocol ScopeListHttpResultData;
@interface ScopeListHttpResultData : JSONModel
@property NSMutableArray<Optional,ScopeListHttpResultDataData> *data;
@property NSString<Optional>*msg;
@property NSString<Optional>*code;
@end
@implementation ScopeListHttpResultData
@synthesize description;
@end

@interface ScopeListHttpResult()
@property ScopeListHttpResultData *data;
@end


@implementation ScopeListHttpCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    ScopeListHttpResult *result = [[ScopeListHttpResult alloc]init];
    result = (ScopeListHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[ScopeListHttpResultData 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 ScopeListHttpResult
- (NSMutableArray *)getScopeListHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    for (int index = 0 ; index < self.data.data.count; index ++) {
        ScopeListHttpResultDataData *httpModel = self.data.data[index];
        ScopeListHttpModel *model = [[ScopeListHttpModel alloc]init];
        model.system = [self getNilString:httpModel.system];
        model.content = [self getNilString:httpModel.content];
        model.sort = [self getNilString:httpModel.sort];
        model.id = [self getNilString:httpModel.id];
        model.createby = [self getNilString:httpModel.createby];
        model.updateon = [self getNilString:httpModel.updateon];
        model.keyword = [self getNilString:httpModel.keyword];
        model.state = [self getNilString:httpModel.state];
        model.updateby = [self getNilString:httpModel.updateby];
        model.name = [self getNilString:httpModel.name];
        model.createon = [self getNilString:httpModel.createon];
        model.type = [self getNilString:httpModel.type];
        [httpArray addObject:model];
    }
    return httpArray;
}
@end
