//
//  AutonomousHttpPostCmd+Response.m
//  MobilePortal
//
//  Created by caiyang on 2020/4/26.
//  Copyright © 2020 yin chen. All rights reserved.
//

#import "AutonomousHttpPostCmd+Response.h"
#import "AutonomousHttpPostCmd.h"
#import "AutonomousHttpPostResult.h"


@protocol AutonomousHttpPostResultDataList;
@interface AutonomousHttpPostResultDataList : 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;
@end
@implementation AutonomousHttpPostResultDataList
@synthesize description;
@end

@protocol AutonomousHttpPostResultDataData;
@interface AutonomousHttpPostResultDataData : JSONModel
@property NSMutableArray<Optional,AutonomousHttpPostResultDataList> *list;
@end
@implementation AutonomousHttpPostResultDataData
@synthesize description;
@end


@protocol AutonomousHttpPostResultData;
@interface AutonomousHttpPostResultData : JSONModel
@property AutonomousHttpPostResultDataData *data;
@end
@implementation AutonomousHttpPostResultData
@synthesize description;
@end

@interface AutonomousHttpPostResult()
@property AutonomousHttpPostResultData *data;
@end

@implementation AutonomousHttpPostCmd (Response)

- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    AutonomousHttpPostResult *result = [[AutonomousHttpPostResult alloc]init];
    result = (AutonomousHttpPostResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[AutonomousHttpPostResultData 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 AutonomousHttpPostResult
- (NSMutableArray *)getAutonomousHttpPostResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    for (int index = 0; index < self.data.data.list.count; index++) {
//        AutonomousHttoModel *model = [[AutonomousHttoModel alloc] init];
        AutonomousHttpPostResultDataList *httpModel = self.data.data.list[index];
        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.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];
        [httpArray addObject:listModel];
    }
    return httpArray;
}
@end
