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

#import "VerificationTokenHttpPostCmd+Response.h"
#import "VerificationTokenHttpPostCmd.h"
#import "VerificationTokenHttpResult.h"


@protocol VerificationTokenHttpResultMessage;
@interface VerificationTokenHttpResultMessage : JSONModel
@property NSString<Optional>*name;
@property NSString<Optional>*count;
@property NSString<Optional>*content;
@end
@implementation VerificationTokenHttpResultMessage
@synthesize description;
@end

@protocol VerificationTokenHttpResultInfo;
@interface VerificationTokenHttpResultInfo : JSONModel
@property NSString<Optional>*isValid;
@property NSString<Optional>*message;
@end
@implementation VerificationTokenHttpResultInfo
@synthesize description;
@end

@protocol VerificationTokenHttpResultDataData;
@interface VerificationTokenHttpResultDataData : JSONModel
@property VerificationTokenHttpResultInfo<Optional>*data;
@property VerificationTokenHttpResultMessage<Optional>*message;
@end
@implementation VerificationTokenHttpResultDataData
@synthesize description;
@end


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

@interface VerificationTokenHttpResult()
@property VerificationTokenHttpResultData *data;
@end


@implementation VerificationTokenHttpPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    VerificationTokenHttpResult *result = [[VerificationTokenHttpResult alloc]init];
    result = (VerificationTokenHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[VerificationTokenHttpResultData 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 VerificationTokenHttpResult
- (NSMutableArray *)getVerificationTokenHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    if (self.data.data && self.data.data.data) {
        if ([self.data.data.data.isValid  isEqualToString:@"1"]) {
            httpArray = [NSMutableArray array];
        } else {
            [httpArray addObject:[self getNilString:self.data.data.data.message]];
        }
    }
    return httpArray;
}
@end
