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

#import "MyApplicationListHttpCmd+Response.h"
#import "MyApplicationListHttpCmd.h"
#import "MyApplicationListHttpResult.h"

@protocol MyApplicationListHttpResultDataList;
@interface MyApplicationListHttpResultDataList : 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>*hightype;

@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>*sysid;
@end
@implementation MyApplicationListHttpResultDataList
@synthesize description;
@end

@protocol MyApplicationListHttpResultData;
@interface MyApplicationListHttpResultData : JSONModel
@property NSMutableArray<Optional,MyApplicationListHttpResultDataList> *application;
@property NSString<Optional>*scope;
@property NSString<Optional>*scopesort;
@end
@implementation MyApplicationListHttpResultData
@synthesize description;
@end

@protocol MyApplicationListHttpResultDataData;
@interface MyApplicationListHttpResultDataData : JSONModel
//@property MyApplicationListHttpResultData *data;
@property NSMutableArray<Optional,MyApplicationListHttpResultData> *data;
@property NSString<Optional>*msg;
@property NSString<Optional>*code;
@end
@implementation MyApplicationListHttpResultDataData
@synthesize description;
@end

@interface MyApplicationListHttpResult()
@property MyApplicationListHttpResultDataData *data;
@end

@implementation MyApplicationListHttpCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    MyApplicationListHttpResult *result = [[MyApplicationListHttpResult alloc]init];
    result = (MyApplicationListHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[MyApplicationListHttpResultDataData 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 MyApplicationListHttpResult
- (NSMutableArray *)getMyApplicationListHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
//    NSError *error;
//    NSString *textFieldContents=[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"mychoice" ofType:@"txt"] encoding:NSUTF8StringEncoding error:&error];
//    MyApplicationListHttpResultDataData *data = [[MyApplicationListHttpResultDataData alloc]initWithString:textFieldContents error:(NSError **)&error];
//    self.data = data;
    for (int index = 0 ; index < self.data.data.count; index ++) {
        @autoreleasepool{
            ApplicationHttpScopListModel *scopList = [[ApplicationHttpScopListModel alloc]init];
            MyApplicationListHttpResultData *httpScopList = self.data.data[index];
            scopList.scope = [self getNilString:httpScopList.scope];
            scopList.scopes = [self getNilString:httpScopList.scopesort];
            [self setScopeArray:scopList.application AndScoprHttpList:httpScopList.application];
            [httpArray addObject:scopList];
        }
    }
    return httpArray;
}
-(void)setScopeArray:(NSMutableArray *)scopeList AndScoprHttpList:(NSMutableArray *)scoprHttpList{
    for (int index = 0; index < scoprHttpList.count; index ++) {
        ApplicationHttpListModel *listModel = [[ApplicationHttpListModel alloc]init];
        MyApplicationListHttpResultDataList *httpModel = scoprHttpList[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.hurl = [self getNilString:httpModel.hurl];
        listModel.iosurl = [self getNilString:httpModel.iosurl];
        listModel.name = [self getNilString:httpModel.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.hightype = [self getNilString:httpModel.hightype];
        listModel.sysid = [self getNilString:httpModel.sysid];
//        listModel.sysid = [self getNilString:httpModel.belong];
        [scopeList addObject:listModel];
    }
}
@end
