//
//  MoreApplicationsHttpCmd+Response.m
//  MobilePortal
//
//  Created by xiejiangbo on 2019/9/21.
//  Copyright © 2019 yin chen. All rights reserved.
//

#import "MoreApplicationsHttpCmd+Response.h"

#import "MoreApplicationsHttpResult.h"


@protocol MoreApplicationsHttpResultDataList;
@interface MoreApplicationsHttpResultDataList : JSONModel
@property NSString<Optional>*docname;
@property NSString<Optional>*status;
@property NSString<Optional>*title;
@property NSString<Optional>*createby;
@property NSString<Optional>*updateby;
@property NSString<Optional>*tags;
@property NSString<Optional>*image;
@property NSString<Optional>*listimage;
@property NSString<Optional>*sort;
@property NSString<Optional>*kgimage;
@property NSString<Optional>*homeshow;
@property NSString<Optional>*createon;
@property NSString<Optional>*updateon;
@property NSString<Optional>*type;
@property NSString<Optional>*id;
@property NSString<Optional>*createbyname;
@property NSString<Optional>*foldertype;
@property NSString<Optional>*updatebyname;
@property NSString<Optional>*comments;
@property NSString<Optional>*pid;
@property NSString<Optional>*author;
@end
@implementation MoreApplicationsHttpResultDataList
@synthesize description;
@end


@protocol MoreApplicationsHttpResultData;
@interface MoreApplicationsHttpResultData : JSONModel
@property NSMutableArray<Optional,MoreApplicationsHttpResultDataList> *list;

@property NSString<Optional>*responseTime;



@end
@implementation MoreApplicationsHttpResultData
@synthesize description;
@end


@interface MoreApplicationsHttpResult()
@property MoreApplicationsHttpResultData *data;
@end


@implementation MoreApplicationsHttpCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    MoreApplicationsHttpResult *result = [[MoreApplicationsHttpResult alloc]init];
    result = (MoreApplicationsHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[MoreApplicationsHttpResultData 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 MoreApplicationsHttpResult
- (NSMutableArray *)getMoreApplicationsHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    MoreApplicationsHttpModel *model = [[MoreApplicationsHttpModel alloc]init];
    for (int index = 0; index < self.data.list.count; index ++) {
        MoreApplicationsHttpListModel *listModel = [[MoreApplicationsHttpListModel alloc]init];
        MoreApplicationsHttpResultDataList *httpModel = self.data.list[index];
        listModel.id = [self getNilString:httpModel.id];
        listModel.title = [self getNilString:httpModel.title];
        listModel.status = [self getNilString:httpModel.status];
        listModel.createon = [self getNilString:httpModel.createon];
        listModel.createby = [self getNilString:httpModel.createby];
        
        listModel.sort = [self getNilString:httpModel.sort];
        listModel.createbyname = [self getNilString:httpModel.createbyname];
        listModel.updatebyname = [self getNilString:httpModel.updatebyname];
        listModel.image = [self getNilString:httpModel.image];
        listModel.image = [self getImageUrl:listModel.image];
        listModel.homeshow = [self getNilString:httpModel.homeshow];
        listModel.comments = [self getNilString:httpModel.comments];
        listModel.docname = [self getNilString:httpModel.docname];
        listModel.type = [self getNilString:httpModel.type];
        listModel.foldertype = [self getNilString:httpModel.foldertype];
        listModel.kgimage = [self getNilString:httpModel.kgimage];
        listModel.listimage = [self getNilString:httpModel.listimage];
        [model.listArray addObject:listModel];
    }
    [httpArray addObject:model];
    return httpArray;
}
@end
