//
//  AccessHttpCmd+Redponses.m
//  MobilePortal
//
//  Created by xiejiangbo on 2020/1/14.
//  Copyright © 2020 yin chen. All rights reserved.
//

#import "AccessHttpCmd+Redponses.h"
#import "AccessHttpResult.h"

@protocol AccessHttpResultData;
@interface AccessHttpResultData : JSONModel
@property NSString<Optional>*isLastPage;
@property NSString<Optional>*pageNum;
@property NSString<Optional>*pages;
@property NSString<Optional>*pageSize;
@property NSString<Optional>*size;
@property NSString<Optional>*status;

@end
@implementation AccessHttpResultData
@synthesize description;
@end


@interface AccessHttpResult()
@property AccessHttpResultData *data;
@end

@implementation AccessHttpCmd (Redponses)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    AccessHttpResult *result = [[AccessHttpResult alloc]init];
    result = (AccessHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[AccessHttpResultData 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 AccessHttpResult
- (NSMutableArray *)getAccessHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    return httpArray;
}
@end
