//
//  UnReadNumberHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2022/6/7.
//  Copyright © 2022 yin chen. All rights reserved.
//

#import "UnReadNumberHttpPostCmd+Response.h"
#import "UnReadNumberHttpPostCmd.h"
#import "UnReadNumberHttpResult.h"

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

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

@interface UnReadNumberHttpResult()
@property UnReadNumberHttpResultData *data;
@end

@implementation UnReadNumberHttpPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    UnReadNumberHttpResult *result = [[UnReadNumberHttpResult alloc]init];
    result = (UnReadNumberHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[UnReadNumberHttpResultData 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 UnReadNumberHttpResult
- (NSMutableArray *)getUnReadNumberHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    if ([self.data.code isEqualToString:@"200"]) {
        httpArray = [NSMutableArray array];
        [AccountInfo sharedInstance].UnReadNumber = self.data.data.ITNum;
//        [AccountInfo sharedInstance].UnReadNumber = @"12";
    } else {
        [httpArray addObject:self.data.msg];
    }
    return httpArray;
}
@end
