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

#import "UpcomingNewListPostCmd+Response.h"
#import "UpcomingNewListPostCmd.h"
#import "UpcomingNewListHttpResult.h"


@protocol UpcomingNewListHttpResultItem;
@interface UpcomingNewListHttpResultItem : JSONModel
@property NSString<Optional>*title;
@property NSString<Optional>*createDate;
@property NSString<Optional>*url;
@end
@implementation UpcomingNewListHttpResultItem
@synthesize description;
@end


@protocol UpcomingNewListHttpResultInfo;
@interface UpcomingNewListHttpResultInfo : JSONModel
@property NSString<Optional>*pageNo;
@property NSString<Optional>*pageSize;
@property NSString<Optional>*userCode;
@property NSString<Optional>*count;
@property NSString<Optional>*key;
@property NSString<Optional>*type;
@property NSMutableArray<UpcomingNewListHttpResultItem,Optional>*list;
@end
@implementation UpcomingNewListHttpResultInfo
@synthesize description;
@end



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

@interface UpcomingNewListHttpResult()
@property UpcomingNewListHttpResultData *data;
@end

@implementation UpcomingNewListPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    UpcomingNewListHttpResult *result = [[UpcomingNewListHttpResult alloc]init];
    result = (UpcomingNewListHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[UpcomingNewListHttpResultData 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 UpcomingNewListHttpResult
- (NSMutableArray *)getUpcomingNewListHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    UpcomingListModel *model = [[UpcomingListModel alloc]init];
    model.pageNum = [self getNilString:self.data.data.pageNo];
    model.pageSize = [self getNilString:self.data.data.pageSize];
    model.total = [self getNilString:self.data.data.count];
    [self setModel:self.data.data.list AndHttpArray:model.list];
    [httpArray addObject:model];
    return httpArray;
}
-(void)setModel:(NSMutableArray *)array AndHttpArray:(NSMutableArray *)httpArray{
    for (int index = 0 ; index < self.data.data.list.count; index ++) {
        UpcomingListItemModel *model = [[UpcomingListItemModel alloc]init];
        UpcomingNewListHttpResultItem *httpModel = self.data.data.list[index];
        model.title = [self getNilString:httpModel.title];
        model.dealtime = [self getNilString:httpModel.createDate];
        model.url = [self getNilString:httpModel.url];
        [httpArray addObject:model];
    }
}
@end
