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

#import "AutonomousCompanyHttpPostCmd+Response.h"
#import "AutonomousCompanyHttpPostCmd.h"
#import "AutonomousCompanyHttpPostResult.h"

@protocol AutonomousCompanyCmdDataSysData;
@interface AutonomousCompanyCmdDataSysData : JSONModel
@property NSString<Optional>*empid;
@property NSString<Optional>*org_service;
@property NSString<Optional>*success;
@property NSString<Optional>*optno;
@property NSString<Optional>*userid;
@property NSString<Optional>*companyid;
@property NSString<Optional>*db_source;
@property NSString<Optional>*createby;
@property NSString<Optional>*updateby;
@property NSString<Optional>*companyname;
@property NSString<Optional>*sysname;
@property NSString<Optional>*createon;
@property NSString<Optional>*id;
@property NSString<Optional>*updateon;
@property NSString<Optional>*omsTestDb;
@property NSString<Optional>*tmsTestDb;
@property NSString<Optional>*cmsTestDb;
@property NSString<Optional>*appTestDb;
@property NSString<Optional>*omsRealDb;
@property NSString<Optional>*tmsRealDb;
@property NSString<Optional>*cmsRealDb;
@property NSString<Optional>*appRealDb;
@property NSString<Optional>*bpmTestDb;
@property NSString<Optional>*bpmRealDb;
@end
@implementation AutonomousCompanyCmdDataSysData
@synthesize description;
@end

@protocol AutonomousCompanyCmdDataSys;
@interface AutonomousCompanyCmdDataSys : JSONModel
@property NSString<Optional>*msg;
@property NSString<Optional>*code;
@property NSString<Optional>*success;
@property NSMutableArray<Optional,AutonomousCompanyCmdDataSysData> *data;
@end
@implementation AutonomousCompanyCmdDataSys
@synthesize description;
@end

@protocol AutonomousCompanyCmdData;
@interface AutonomousCompanyCmdData : JSONModel
@property AutonomousCompanyCmdDataSys *sysCompany;
@end
@implementation AutonomousCompanyCmdData
@synthesize description;
@end


@interface AutonomousCompanyHttpPostResult()
@property AutonomousCompanyCmdData *data;
@end

@implementation AutonomousCompanyHttpPostCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    AutonomousCompanyHttpPostResult *result = [[AutonomousCompanyHttpPostResult alloc]init];
    result = (AutonomousCompanyHttpPostResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[AutonomousCompanyCmdData 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 AutonomousCompanyHttpPostResult
- (NSMutableArray *)getAutonomousCompanyHttpPostResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    if (!self.data) {
        return httpArray;
    }
    for (int index = 0; index < self.data.sysCompany.data.count; index++) {
        AutonomousCompanyModel *model = [[AutonomousCompanyModel alloc]init];
        AutonomousCompanyCmdDataSysData *httpModel = self.data.sysCompany.data[index];
        model.empid = [self getNilString:httpModel.empid];
        model.org_service = [self getNilString:httpModel.org_service];
        model.optno = [self getNilString:httpModel.optno];
        model.userid = [self getNilString:httpModel.userid];
        model.companyid = [self getNilString:httpModel.companyid];
        model.db_source = [self getNilString:httpModel.db_source];
        model.createby = [self getNilString:httpModel.createby];
        model.updateby = [self getNilString:httpModel.updateby];
        model.companyname = [self getNilString:httpModel.companyname];
        model.sysname = [self getNilString:httpModel.sysname];
        model.createon = [self getNilString:httpModel.createon];
        model.id = [self getNilString:httpModel.id];
        model.updateon = [self getNilString:httpModel.updateon];
        model.omsTestDb = [self getNilString:httpModel.omsTestDb];
        model.tmsTestDb = [self getNilString:httpModel.tmsTestDb];
        model.cmsTestDb = [self getNilString:httpModel.cmsTestDb];
        model.appTestDb = [self getNilString:httpModel.appTestDb];
        model.omsRealDb = [self getNilString:httpModel.omsRealDb];
        model.tmsRealDb = [self getNilString:httpModel.tmsRealDb];
        model.cmsRealDb = [self getNilString:httpModel.cmsRealDb];
        model.appRealDb = [self getNilString:httpModel.appRealDb];
        model.bpmTestDb = [self getNilString:httpModel.bpmTestDb];
        model.bpmRealDb = [self getNilString:httpModel.bpmRealDb];
        [httpArray addObject:model];
    }
    return httpArray;
}
@end
