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

#import "SinglePointInfoHttpPostCmd+Response.h"
#import "SinglePointInfoHttpPostCmd.h"
#import "SinglePointinfoHttpResult.h"

@protocol SinglePointinfoHttpResultInfoAttributes;
@interface SinglePointinfoHttpResultInfoAttributes : JSONModel
@property NSArray<Optional>*spRoleList;
@property NSString<Optional>*displayName;
@end
@implementation SinglePointinfoHttpResultInfoAttributes
@synthesize description;
@end

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

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

@protocol SinglePointinfoHttpResultDataData;
@interface SinglePointinfoHttpResultDataData : JSONModel
@property SinglePointinfoHttpResultInfo<Optional>*data;
@property SinglePointinfoHttpResultMessage<Optional>*message;
@end
@implementation SinglePointinfoHttpResultDataData
@synthesize description;
@end


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

@interface SinglePointinfoHttpResult()
@property SinglePointinfoHttpResultData *data;
@end


@implementation SinglePointInfoHttpPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    SinglePointinfoHttpResult *result = [[SinglePointinfoHttpResult alloc]init];
    result = (SinglePointinfoHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[SinglePointinfoHttpResultData 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 SinglePointinfoHttpResult
- (NSMutableArray *)getSinglePointinfoHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    if (self.data.data.data.attributes && self.data.data.data.attributes.spRoleList) {
        [AccountInfo sharedInstance].UserId = self.data.data.data.attributes.spRoleList.firstObject;
        httpArray = [NSMutableArray array];
    } else {
        [SMAlertView showOnlyButtonAlert:[NSString stringWithFormat:@"%@(%@)",self.data.data.message.name,self.data.data.message.content] title:@"请求失败"];
        [httpArray addObject:self.data.data.message.name];
    }
    return httpArray;
}
@end
