//
//  WeChatBindingHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2020/5/9.
//  Copyright © 2020 yin chen. All rights reserved.
//

#import "WeChatBindingHttpPostCmd+Response.h"
#import "WeChatBindingHttpPostCmd.h"
#import "WeChatBindingHttpResult.h"

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

@interface WeChatBindingHttpResult()
@property WeChatBindingHttpResultData *data;
@end


@implementation WeChatBindingHttpPostCmd (Response)

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