//
//  RefreshTokenHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2021/1/4.
//  Copyright © 2021 yin chen. All rights reserved.
//

#import "RefreshTokenHttpPostCmd+Response.h"
#import "RefreshTokenHttpPostCmd.h"
#import "RefeshTokenHttpResult.h"

@protocol RefeshTokenHttpResultDataData;
@interface RefeshTokenHttpResultDataData : JSONModel
@property NSString<Optional>*tokenId;
@property NSString<Optional>*appCopyright;
@property NSString<Optional>*appHostGUID;
@property NSString<Optional>*appVersion;
@property NSString<Optional>*errorName;

@end
@implementation RefeshTokenHttpResultDataData
@synthesize description;
@end


@protocol RefeshTokenHttpResultData;
@interface RefeshTokenHttpResultData : JSONModel
@property NSString<Optional>*code;
@property NSString<Optional>*msg;

@property RefeshTokenHttpResultDataData<Optional>*data;
@end
@implementation RefeshTokenHttpResultData
@synthesize description;
@end

@interface RefeshTokenHttpResult()
@property RefeshTokenHttpResultData *data;
@end



@implementation RefreshTokenHttpPostCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    RefeshTokenHttpResult *result = [[RefeshTokenHttpResult alloc]init];
    result = (RefeshTokenHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[RefeshTokenHttpResultData 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 RefeshTokenHttpResult
- (NSMutableArray *)getRefeshTokenHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    if ([self.data.code isEqualToString:@"200"]) {
        [AccountInfo sharedInstance].singlePoint_access_token = [self getNilString:self.data.data.tokenId];
    } else if ([self.data.code isEqualToString:@"501"]) {
        [httpArray addObject:self.data.msg];
    } else if ([self.data.code isEqualToString:@"500"]) {
        [httpArray addObject:self.data.msg];
    }
    return httpArray;
}
@end
