//
//  AllApplicationHttpListCmd+Response.m
//  MobilePortal
//
//  Created by xiejiangbo on 2019/10/28.
//  Copyright © 2019 yin chen. All rights reserved.
//

#import "AllApplicationHttpListCmd+Response.h"
#import "AllApplicationHttpListResult.h"

@protocol AllApplicationHttpListResultDataList;
@interface AllApplicationHttpListResultDataList : JSONModel
@property NSString<Optional>*applicationid;
@property NSString<Optional>*createby;
@property NSString<Optional>*updateby;
@property NSString<Optional>*status;
@property NSString<Optional>*iconurl;
@property NSString<Optional>*partstate;
@property NSString<Optional>*belong;
@property NSString<Optional>*hurl;
@property NSString<Optional>*iosurl;
@property NSString<Optional>*name;
@property NSString<Optional>*hversion;
@property NSString<Optional>*createon;
@property NSString<Optional>*updateon;
@property NSString<Optional>*companystate;
@property NSString<Optional>*androidurl;
@property NSString<Optional>*scope;
@property NSString<Optional>*scopes;
@property NSString<Optional>*androidversion;
@property NSString<Optional>*pointstate;
@property NSString<Optional>*platforms;
@property NSString<Optional>*empuidstate;
@property NSString<Optional>*passstate;
@property NSString<Optional>*iosversion;
@property NSString<Optional>*introduce;
@property NSString<Optional>*htitle;
@property NSString<Optional>*androidname;
@property NSString<Optional>*androidcontent;
@property NSString<Optional>*iosbundieid;
@property NSString<Optional>*iosopenurl;
@property NSString<Optional>*ioscontent;
@property NSString<Optional>*hcontent;

@property NSString<Optional>*value1;
@property NSString<Optional>*value2;
@property NSString<Optional>*value3;
@property NSString<Optional>*value4;
@property NSString<Optional>*value5;
@property NSString<Optional>*appid;
@property NSString<Optional>*image;
@property NSString<Optional>*title;
@property NSString<Optional>*tags;

@property NSString<Optional>*todotype;
@property NSString<Optional>*todokey;
@property NSString<Optional>*sysid;
@end
@implementation AllApplicationHttpListResultDataList
@synthesize description;
@end


@protocol AllApplicationHttpListResultData;
@interface AllApplicationHttpListResultData : JSONModel

@property NSString<Optional>*pageNum;
@property NSString<Optional>*pages;
@property NSString<Optional>*pageSize;
@property NSString<Optional>*size;
@property NSString<Optional>*status;
@property NSMutableArray<Optional,AllApplicationHttpListResultDataList> *list;
@end
@implementation AllApplicationHttpListResultData
@synthesize description;
@end

@protocol AllApplicationHttpListResultDataData;
@interface AllApplicationHttpListResultDataData : JSONModel
@property AllApplicationHttpListResultData *data;
@end
@implementation AllApplicationHttpListResultDataData
@synthesize description;
@end

@interface AllApplicationHttpListResult()
@property AllApplicationHttpListResultDataData *data;
@end

@implementation AllApplicationHttpListCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    AllApplicationHttpListResult *result = [[AllApplicationHttpListResult alloc]init];
    result = (AllApplicationHttpListResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[AllApplicationHttpListResultDataData 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 AllApplicationHttpListResult
- (NSMutableArray *)getAllApplicationHttpListResult{
//    NSError *error;
//    NSString *textFieldContents=[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"queryReleasedAll" ofType:@"txt"] encoding:NSUTF8StringEncoding error:&error];
//    AllApplicationHttpListResultData *data = [[AllApplicationHttpListResultData alloc]initWithString:textFieldContents error:(NSError **)&error];
//    self.data.data = data;
//    NSLog(@"%lu",data.list.count);
    NSMutableArray *httpArray = [NSMutableArray array];
    for (int index = 0; index < self.data.data.list.count; index ++) {
        @autoreleasepool{
            ApplicationHttpListModel *listModel = [[ApplicationHttpListModel alloc]init];
            AllApplicationHttpListResultDataList *httpModel = self.data.data.list[index];
            listModel.applicationid = [self getNilString:httpModel.applicationid];
            listModel.createby = [self getNilString:httpModel.createby];
            listModel.updateby = [self getNilString:httpModel.updateby];
            listModel.status = [self getNilString:httpModel.status];
            listModel.iconurl = [self getNilString:httpModel.iconurl];
            listModel.imageUrl = [self getImageUrl:listModel.iconurl];
            listModel.partstate = [self getNilString:httpModel.partstate];
            listModel.belong = [self getNilString:httpModel.belong];
            //        listModel.belong = [self getNilString:httpModel.tags];
            
            listModel.hurl = [self getNilString:httpModel.hurl];
            listModel.iosurl = [self getNilString:httpModel.iosurl];
            listModel.name = [self getNilString:httpModel.name];
            listModel.name = [self getNilString:httpModel.name];
            //        NSLog(@"%@",listModel.name);
            listModel.hversion = [self getNilString:httpModel.hversion];
            listModel.createon = [self getNilString:httpModel.createon];
            listModel.updateon = [self getNilString:httpModel.updateon];
            listModel.companystate = [self getNilString:httpModel.companystate];
            listModel.androidurl = [self getNilString:httpModel.androidurl];
            listModel.scope = [self getNilString:httpModel.scope];
            listModel.scopes = [self getNilString:httpModel.scopes];
            listModel.androidversion = [self getNilString:httpModel.androidversion];
            listModel.pointstate = [self getNilString:httpModel.pointstate];
            listModel.platforms = [self getNilString:httpModel.platforms];
            listModel.empuidstate = [self getNilString:httpModel.empuidstate];
            listModel.passstate = [self getNilString:httpModel.passstate];
            listModel.iosversion = [self getNilString:httpModel.iosversion];
            listModel.introduce = [self getNilString:httpModel.introduce];
            listModel.ioscontent = [self getNilString:httpModel.ioscontent];
            listModel.iosbundieid = [self getNilString:httpModel.iosbundieid];
            listModel.iosopenurl = [self getNilString:httpModel.iosopenurl];
            if ([listModel.iosopenurl rangeOfString:@"://"].location == NSNotFound && ![listModel.iosopenurl isEqualToString:@""]) {
                listModel.iosopenurl = [NSString stringWithFormat:@"%@://",listModel.iosopenurl];
            }
            listModel.androidname = [self getNilString:httpModel.androidname];
            listModel.androidcontent = [self getNilString:httpModel.androidcontent];
            listModel.hcontent = [self getNilString:httpModel.hcontent];
            listModel.htitle = [self getNilString:httpModel.htitle];
            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.appid = [self getNilString:httpModel.appid];
            listModel.todotype = [self getNilString:httpModel.todotype];
            listModel.todokey = [self getNilString:httpModel.todokey];
            listModel.sysid = [self getNilString:httpModel.sysid];
//            listModel.sysid = [self getNilString:httpModel.belong];
            [httpArray addObject:listModel];
        }
        
    }
    return httpArray;
}
@end
