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

#import "SinglePointLoginHttpPostCmd+Response.h"

#import "SinglePointLoginHttpPostCmd.h"
#import "SinglePointLoginHttpResult.h"

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

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


@protocol SinglePointLoginHttpResultDataData;
@interface SinglePointLoginHttpResultDataData : JSONModel
@property SinglePointLoginHttpResultInfo<Optional>*data;
@property SinglePointLoginHttpResultMessage<Optional>*message;
@end
@implementation SinglePointLoginHttpResultDataData
@synthesize description;
@end


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

@interface SinglePointLoginHttpResult()
@property SinglePointLoginHttpResultData *data;
@end


@implementation SinglePointLoginHttpPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    SinglePointLoginHttpResult *result = [[SinglePointLoginHttpResult alloc]init];
    result = (SinglePointLoginHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[SinglePointLoginHttpResultData 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 SinglePointLoginHttpResult
- (NSMutableArray *)getSinglePointLoginHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    if (![self.data.code isEqualToString:@"200"] && self.data.data.message.name) {
        [httpArray addObject:@"1"];
        [SMAlertView showOnlyButtonAlert:[NSString stringWithFormat:@"%@（%@）",self.data.data.message.name,self.data.data.message.content] title:@"IDM登录失败"];
    } else if (self.data.data.data.tokenId) {
        [AccountInfo sharedInstance].singlePoint_access_token = self.data.data.data.tokenId;
    }
    return httpArray;
}
@end
