//
//  LoginTypeHttpGetCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2020/9/14.
//  Copyright © 2020 yin chen. All rights reserved.
//

#import "LoginTypeHttpGetCmd+Response.h"
#import "LoginTypeHttpGetCmd.h"
#import "LoginTypeHttpResult.h"

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

@interface LoginTypeHttpResult()
@property LoginTypeHttpResultData *data;
@end

@implementation LoginTypeHttpGetCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    LoginTypeHttpResult *result = [[LoginTypeHttpResult alloc]init];
    result = (LoginTypeHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[LoginTypeHttpResultData 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 LoginTypeHttpResult
- (NSMutableArray *)getLoginTypeHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    if ([self.data.code isEqualToString:@"200"]) {
        [httpArray addObject:self.data.data];
    } else {
//        SMToastView.showMessage("密码不能为空")
        [SMToastView showMessage:self.data.msg];
//        [SMAlertView showOnlyButtonAlert: title:@"IDM登录失败"];
//        [SMAlertView showOnlyButtonAlert:[self getNilString:self.data.msg] title:@"登录失败"];
    }
    return httpArray;
}
@end
