//
//  MyApplicationsHttpCmd+Response.m
//  MobilePortal
//
//  Created by xiejiangbo on 2019/3/18.
//  Copyright © 2019 yin chen. All rights reserved.
//

#import "MyApplicationsHttpCmd+Response.h"
#import "MyApplicationsHttpResult.h"

@protocol MyApplicationsHttpResultDataList;
@interface MyApplicationsHttpResultDataList : 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;
@property NSString<Optional>*openurl;
@property NSString<Optional>*appid;
@property NSString<Optional>*value1;
@property NSString<Optional>*value2;
@property NSString<Optional>*value3;
@property NSString<Optional>*value4;
@property NSString<Optional>*value5;
@end
@implementation MyApplicationsHttpResultDataList
@synthesize description;
@end

@protocol MyApplicationsHttpResultData;
@interface MyApplicationsHttpResultData : JSONModel
@property NSMutableArray<Optional,MyApplicationsHttpResultDataList> *list;
@property NSString<Optional>*responseTime;
@end
@implementation MyApplicationsHttpResultData
@synthesize description;
@end


@interface MyApplicationsHttpResult()
@property MyApplicationsHttpResultData *data;
@end


@implementation MyApplicationsHttpCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    MyApplicationsHttpResult *result = [[MyApplicationsHttpResult alloc]init];
    result = (MyApplicationsHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[MyApplicationsHttpResultData 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 MyApplicationsHttpResult
- (NSMutableArray *)getMyApplicationsHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    MyApplicationsHttpModel *model = [[MyApplicationsHttpModel alloc]init];
    for (int index = 0; index < self.data.list.count; index ++) {
//        AdvisoryHttpListModel *listModel = [[AdvisoryHttpListModel alloc]init];
        ApplicationHttpListModel *listModel = [[ApplicationHttpListModel alloc]init];
        MyApplicationsHttpResultDataList *httpModel = self.data.list[index];
        listModel.id = [self getNilString:httpModel.id];
        listModel.title = [self getNilString:httpModel.title];
        listModel.name = [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.imageUrl = [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];
        listModel.tags = [self getNilString:httpModel.tags];
        listModel.belong = [self getNilString:httpModel.tags];
        listModel.openurl = [self getNilString:httpModel.openurl];
        listModel.appid = [self getNilString:httpModel.appid];
        listModel.value1 = [self getNilString:httpModel.value1];
        listModel.value2 = [self getNilString:httpModel.value2];
        listModel.value3 = [self getNilString:httpModel.value3];
        listModel.value4 = [self getNilString:httpModel.value4];
        listModel.value5 = [self getNilString:httpModel.value5];
        listModel.iosopenurl = [self getNilString:httpModel.openurl];
        [model.listArray addObject:listModel];
    }
    [httpArray addObject:model];
    return httpArray;
}
@end
