//
//  MyUpcomingListHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2020/5/6.
//  Copyright © 2020 yin chen. All rights reserved.
//

#import "MyUpcomingListHttpPostCmd+Response.h"
#import "MyUpcomingListHttpPostCmd.h"
#import "MyUpcomingListHttpResult.h"


@protocol MyUpcomingListHttpResultDataData;
@interface MyUpcomingListHttpResultDataData : JSONModel
@property NSString<Optional>*id;
@property NSString<Optional>*title;
@property NSString<Optional>*msgtime;
@property NSString<Optional>*dealtime;
@property NSString<Optional>*targetid;
@property NSString<Optional>*type;
@property NSString<Optional>*state;
@property NSString<Optional>*msgid;
@property NSString<Optional>*approvalrole;
@property NSString<Optional>*approvalid;
@property NSString<Optional>*system;
@property NSString<Optional>*attr1;
@property NSString<Optional>*attr2;
@property NSString<Optional>*status;
@property NSString<Optional>*count;
@property NSString<Optional>*datetime;
@end
@implementation MyUpcomingListHttpResultDataData
@synthesize description;
@end

@protocol MyUpcomingListHttpResultDataList;
@interface MyUpcomingListHttpResultDataList : JSONModel
@property NSMutableArray<Optional,MyUpcomingListHttpResultDataData> *list;
@property NSString<Optional>*msg;
@property NSString<Optional>*pageNum;
@property NSString<Optional>*pageSize;
@property NSString<Optional>*size;
@property NSString<Optional>*startRow;
@property NSString<Optional>*endRow;
@property NSString<Optional>*total;
@property NSString<Optional>*pages;
@property NSString<Optional>*isLastPage;
@end
@implementation MyUpcomingListHttpResultDataList
@synthesize description;
@end

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

@interface MyUpcomingListHttpResult()
@property MyUpcomingListHttpResultData *data;
@end


@implementation MyUpcomingListHttpPostCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    MyUpcomingListHttpResult *result = [[MyUpcomingListHttpResult alloc]init];
    result = (MyUpcomingListHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[MyUpcomingListHttpResultData 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 MyUpcomingListHttpResult
- (NSMutableArray *)getMyUpcomingListHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    UpcomingListModel *model = [[UpcomingListModel alloc]init];
    model.pageNum = [self getNilString:self.data.data.pageNum];
    model.pageSize = [self getNilString:self.data.data.pageSize];
    model.size = [self getNilString:self.data.data.size];
    model.startRow = [self getNilString:self.data.data.startRow];
    model.endRow = [self getNilString:self.data.data.endRow];
    model.total = [self getNilString:self.data.data.total];
    model.pages = [self getNilString:self.data.data.pages];
    model.isLastPage = [self getNilString:self.data.data.isLastPage];
    [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];
        MyUpcomingListHttpResultDataData *httpModel = self.data.data.list[index];
        model.id = [self getNilString:httpModel.id];
        model.title = [self getNilString:httpModel.title];
        model.msgtime = [self getNilString:httpModel.msgtime];
        model.dealtime = [self getNilString:httpModel.dealtime];
        model.targetid = [self getNilString:httpModel.targetid];
        model.type = [self getNilString:httpModel.type];
        model.state = [self getNilString:httpModel.state];
        model.msgid = [self getNilString:httpModel.msgid];
        model.approvalrole = [self getNilString:httpModel.approvalrole];
        model.approvalid = [self getNilString:httpModel.approvalid];
        model.system = [self getNilString:httpModel.system];
        model.attr1 = [self getNilString:httpModel.attr1];
        model.attr2 = [self getNilString:httpModel.attr2];
        model.status = [self getNilString:httpModel.status];
        model.datetime = [self getNilString:httpModel.datetime];
        [httpArray addObject:model];
    }
}
@end
