//
//  ChangePasswordHttpCmd+Response.m
//  MobilePortal
//
//  Created by xiejiangbo on 2019/6/28.
//  Copyright © 2019 yin chen. All rights reserved.
//

#import "ChangePasswordHttpCmd+Response.h"
#import "ChangePasswordHttpResult.h"

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


@protocol ChangePasswordHttpPostResultData;
@interface ChangePasswordHttpPostResultData : JSONModel
@property NSMutableArray<Optional,ChangePasswordHttpPostResultDataData> *data;
@property NSString<Optional>*code;
@property NSString<Optional>*msg;
@property NSString<Optional>*success;
//@property ChangePasswordHttpPostResultDataData *data;
@end
@implementation ChangePasswordHttpPostResultData
@synthesize description;
@end


@interface ChangePasswordHttpResult()
@property ChangePasswordHttpPostResultData *data;
@end


@implementation ChangePasswordHttpCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    ChangePasswordHttpResult *result = [[ChangePasswordHttpResult alloc]init];
    result = (ChangePasswordHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[ChangePasswordHttpPostResultData 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 ChangePasswordHttpResult
- (NSMutableArray *)getChangePasswordHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    for (int index = 0; index<self.data.data.count; index ++) {
        ChangePasswordHttpPostResultDataData *model = self.data.data[index];
        [httpArray addObject:model.message];
        if ([model.result isEqualToString:@"1"]) {
            httpArray = [NSMutableArray array];
        }
    }
    return httpArray;
}
@end

