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

#import "SinglePointPasswordHttpPostCmd+Response.h"
#import "SinglePointPasswordHttpPostCmd.h"
#import "SinglePointPasswordHttpResult.h"

@protocol SinglePointPasswordHttpResultError;
@interface SinglePointPasswordHttpResultError : JSONModel
@property NSString<Optional>*trace;
@property NSString<Optional>*name;
@property NSString<Optional>*message;

@end
@implementation SinglePointPasswordHttpResultError
@synthesize description;
@end

@protocol SinglePointPasswordHttpResultDataData;
@interface SinglePointPasswordHttpResultDataData : JSONModel
@property NSString<Optional>*errorName;
@property NSString<Optional>*success;
@property NSString<Optional>*errorMessage;
@property NSString<Optional>*errorCode;
@property SinglePointPasswordHttpResultError<Optional>*errorException;
@end
@implementation SinglePointPasswordHttpResultDataData
@synthesize description;
@end


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

@interface SinglePointPasswordHttpResult()
@property SinglePointPasswordHttpResultData *data;
@end


@implementation SinglePointPasswordHttpPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    SinglePointPasswordHttpResult *result = [[SinglePointPasswordHttpResult alloc]init];
    result = (SinglePointPasswordHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[SinglePointPasswordHttpResultData 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 SinglePointPasswordHttpResult
- (NSMutableArray *)getSinglePointPasswordHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    if (self.data.data) {
        if ([self.data.data.success isEqualToString:@"1"]) {
            httpArray = [NSMutableArray array];
        } else {
            [SMAlertView showOnlyButtonAlert:[NSString stringWithFormat:@"%@(%@)",self.data.data.errorException.message,self.data.data.errorException.name] title:@"密码修改失败！"];
            [httpArray addObject:self.data.data.errorMessage];
        }
    }
    return httpArray;
}
@end
