//
//  JuphRegistrationIDHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2021/10/19.
//  Copyright © 2021 yin chen. All rights reserved.
//

#import "JuphRegistrationIDHttpPostCmd+Response.h"
#import "JuphRegistrationIDHttpPostCmd.h"
#import "JuphRegistrationIDHttpResult.h"

@protocol JuphRegistrationIDHttpResultDataData;
@interface JuphRegistrationIDHttpResultDataData : JSONModel
@property NSString<Optional>*empid;
@end
@implementation JuphRegistrationIDHttpResultDataData
@synthesize description;
@end

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

@interface JuphRegistrationIDHttpResult()
@property JuphRegistrationIDHttpResultData *data;
@end


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