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

#import "SelectCompanyHttpCmd+Response.h"
#import "SelectCompanyHttpResult.h"

@protocol SelectCompanyHttpResultCompanyListData;
@interface SelectCompanyHttpResultCompanyListData : JSONModel
@property NSString<Optional>*empid;
@property NSString<Optional>*org_service;
@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>*cmsRealDb;
@property NSString<Optional>*cmsTestDb;
@property NSString<Optional>*omsTestDb;
@property NSString<Optional>*omsRealDb;
@property NSString<Optional>*tmsRealDb;
@property NSString<Optional>*tmsTestDb;
@property NSString<Optional>*appRealDb;
@property NSString<Optional>*appTestDb;
@property NSString<Optional>*tms_version;
@end
@implementation SelectCompanyHttpResultCompanyListData
@synthesize description;
@end

@protocol SelectCompanyHttpResultOrgListData;
@interface SelectCompanyHttpResultOrgListData : JSONModel
@property NSString<Optional>*partyName;
@property NSString<Optional>*emp;
@property NSString<Optional>*partyOpcode;
@property NSString<Optional>*org;
@end
@implementation SelectCompanyHttpResultOrgListData
@synthesize description;
@end

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

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

@protocol SelectCompanyHttpResultData;
@interface SelectCompanyHttpResultData : JSONModel
@property SelectCompanyHttpResultOrgList *orgList;
@property SelectCompanyHttpResultCompanyList *sysCompany;
@property NSString<Optional>*companyname;

@end
@implementation SelectCompanyHttpResultData
@synthesize description;
@end


@interface SelectCompanyHttpResult()
@property SelectCompanyHttpResultData *data;
@end

@implementation SelectCompanyHttpCmd (Response)
- (void)onRequestSuccess:(id)request code:(NSInteger)code{
    
    [self.result setResultState:kRequestResultSuccess];
    NSDictionary *dic = (NSDictionary *)request;
    SelectCompanyHttpResult *result = [[SelectCompanyHttpResult alloc]init];
    result = (SelectCompanyHttpResult *)self.result;
    if (code>199&&code<299) {
        [self.result setResultState:kRequestResultSuccess];
        NSError *error;
        result.data = [[SelectCompanyHttpResultData alloc]initWithDictionary:dic error:(NSError **)&error];
        if(error){
            LYLSLog(@"error=====:%@",[self DataTOjsonString:dic]);
            [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);
    }
}
-(NSString*)DataTOjsonString:(id)object
{
    NSString *jsonString = nil;
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
                                                       options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
                                                         error:&error];
    if (! jsonData) {
        NSLog(@"Got an error: %@", error);
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    return jsonString;
}
- (void)onRequestFailed:(NSError *)error{
    NSLog(@"Error===%@",error);
    [self.result setErrMsg:[error localizedDescription]];
    [self.result setResultState:kRequestResultFail];
}
    @end
@implementation SelectCompanyHttpResult
- (NSMutableArray *)getSelectCompanyHttpResult{
    NSMutableArray *httpArray = [NSMutableArray array];
    SelectCompanyHttpModel *model = [[SelectCompanyHttpModel alloc]init];
    model.companyname = [self getNilString:self.data.companyname];
    model.orgList.msg = [self getNilString:self.data.orgList.msg];
    model.orgList.code = [self getNilString:self.data.orgList.code];
    model.orgList.success = [self getNilString:self.data.orgList.success];
    for (int index = 0; index < self.data.orgList.data.count; index ++) {
        SelectCompanyHttpOrgListDataModel *orgListDataModel = [[SelectCompanyHttpOrgListDataModel alloc]init];
        SelectCompanyHttpResultOrgListData *httpModel = self.data.orgList.data[index];
        orgListDataModel.partyName = [self getNilString:httpModel.partyName];
        orgListDataModel.emp = [self getNilString:httpModel.emp];
        orgListDataModel.partyOpcode = [self getNilString:httpModel.partyOpcode];
        orgListDataModel.org = [self getNilString:httpModel.org];
        [model.orgList.data addObject:orgListDataModel];
    }
    model.sysCompany.msg = [self getNilString:self.data.sysCompany.msg];
    model.sysCompany.code = [self getNilString:self.data.sysCompany.code];
    model.sysCompany.success = [self getNilString:self.data.sysCompany.success];
    for (int index = 0; index < self.data.sysCompany.data.count; index ++) {
        SelectCompanyHttpCompanyDataModel *companyDataModel = [[SelectCompanyHttpCompanyDataModel alloc]init];
        SelectCompanyHttpResultCompanyListData *httpModel = self.data.sysCompany.data[index];
        companyDataModel.empid = [self getNilString:httpModel.empid];
        companyDataModel.org_service = [self getNilString:httpModel.org_service];
        companyDataModel.optno = [self getNilString:httpModel.optno];
        companyDataModel.userid = [self getNilString:httpModel.userid];
        companyDataModel.companyid = [self getNilString:httpModel.companyid];
        companyDataModel.db_source = [self getNilString:httpModel.db_source];
        companyDataModel.createby = [self getNilString:httpModel.createby];
        companyDataModel.updateby = [self getNilString:httpModel.updateby];
        companyDataModel.companyname = [self getNilString:httpModel.companyname];
        companyDataModel.sysname = [self getNilString:httpModel.sysname];
        companyDataModel.createon = [self getNilString:httpModel.createon];
        companyDataModel.id = [self getNilString:httpModel.id];
        companyDataModel.updateon = [self getNilString:httpModel.updateon];
        
        companyDataModel.cmsRealDb = [self getNilString:httpModel.cmsRealDb];
        companyDataModel.cmsTestDb = [self getNilString:httpModel.cmsTestDb];
        companyDataModel.omsTestDb = [self getNilString:httpModel.omsTestDb];
        companyDataModel.omsRealDb = [self getNilString:httpModel.omsRealDb];
        companyDataModel.tmsRealDb = [self getNilString:httpModel.tmsRealDb];
        companyDataModel.tmsTestDb = [self getNilString:httpModel.tmsTestDb];
        companyDataModel.appRealDb = [self getNilString:httpModel.appRealDb];
        companyDataModel.appTestDb = [self getNilString:httpModel.appTestDb];
        
        companyDataModel.tms_version = [self getNilString:httpModel.tms_version];
        [model.sysCompany.data addObject:companyDataModel];
    }
    [httpArray addObject:model];
    return httpArray;
}
    @end
