//
//  UpcomingNewCountHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2020/11/16.
//  Copyright © 2020 yin chen. All rights reserved.
//

#import "UpcomingNewCountHttpPostCmd+Response.h"
#import "UpcomingNewCountHttpPostCmd.h"
#import "UpcomingNewCountHttpResult.h"

@protocol UpcomingNewCountHttpResultDataData;
@interface UpcomingNewCountHttpResultDataData : JSONModel
@property NSString<Optional>*key;
@property NSString<Optional>*type;
@property NSString<Optional>*count;
@end
@implementation UpcomingNewCountHttpResultDataData
@synthesize description;
@end

@protocol UpcomingNewCountHttpResultData;
@interface UpcomingNewCountHttpResultData : JSONModel
@property NSMutableArray <UpcomingNewCountHttpResultDataData,Optional>*data;
@property NSString<Optional>*msg;
@property NSString<Optional>*code;
@end
@implementation UpcomingNewCountHttpResultData
@synthesize description;
@end

@interface UpcomingNewCountHttpResult()
@property UpcomingNewCountHttpResultData *data;
@end



@implementation UpcomingNewCountHttpPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    UpcomingNewCountHttpResult *result = [[UpcomingNewCountHttpResult alloc]init];
    result = (UpcomingNewCountHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[UpcomingNewCountHttpResultData 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 UpcomingNewCountHttpResult
- (NSMutableArray *)getUpcomingNewCountHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    for (int index = 0; index < self.data.data.count; index ++) {
        UpcomingNewCountModel *model = [[UpcomingNewCountModel alloc]init];
        UpcomingNewCountHttpResultDataData *httpmodel = self.data.data[index];
        model.key = [self getNilString:httpmodel.key];
        model.type = [self getNilString:httpmodel.type];
        model.count = [self getNilString:httpmodel.count];
        [httpArray addObject:model];
    }
    return httpArray;
}
@end
