//
//  AccountConfigModel.m
//  Patrol
//
//  Created by 曹云霄 on 2017/8/10.
//  Copyright © 2017年 上海勾芒科技有限公司. All rights reserved.
//

#import "AccountConfigModel.h"

@implementation AccountConfigModel


/**
 解析
 */
- (void)analysisConfigModel
{
    for (AccountConfigModel_data *item in self.data) {
        NSData *jsonData = [item.optionValue dataUsingEncoding:NSUTF8StringEncoding];
        NSArray *array = [NSJSONSerialization JSONObjectWithData:jsonData
                                                         options:NSJSONReadingMutableContainers
                                                           error:nil];
        //保修费用类型
        if ([item.optionKey isEqualToString:@"repairFeeType"]) {
            NSMutableArray *configArray = [NSMutableArray array];
            for (NSDictionary *dict in array) {
                PublicConfigModel *model = [[PublicConfigModel alloc] initWithDictionary:dict error:nil];
                [configArray addObject:model];
            }
            AccountConfigModel_repairFeeType *repairFeeType = [[AccountConfigModel_repairFeeType alloc] init];
            repairFeeType.repairFeeTypeArray = (NSArray<PublicConfigModel> *)configArray;
            self.repairFeeType = repairFeeType;
        //门店类型
        }else if ([item.optionKey isEqualToString:@"storeType"]) {
            NSMutableArray *configArray = [NSMutableArray array];
            for (NSDictionary *dict in array) {
                PublicConfigModel *model = [[PublicConfigModel alloc] initWithDictionary:dict error:nil];
                [configArray addObject:model];
            }
            AccountConfigModel_storeType *storeType = [[AccountConfigModel_storeType alloc] init];
            storeType.storeTypeArray = (NSArray<PublicConfigModel> *)configArray;
            self.storeType = storeType;
        //是否启用OSS
        }else if ([item.optionKey isEqualToString:@"enableoss"]) {
            NSString *string = @"{\"accessKey\":\"LTAIiRWdyPrLTinG\",\"secretKey\":\"nWBZDNaGf6CWL8FhQt0eJB8Y0xpUOd\",\"endPoint\":\"oss-cn-shanghai.aliyuncs.com\",\"bucketName\":\"total-gomore\", \"region\":\"oss-cn-shanghai\",\"imgEndpoint\":\"total-gomore.img-cn-shanghai.aliyuncs.com\", \"width\":\"200\", \"height\":\"200\"}";
            
            AccountConfigModel_uploadType *uploadType = [[AccountConfigModel_uploadType alloc] initWithString:string error:nil];
            if ([uploadType.ossType isEqualToString:@"COS"]) {
                uploadType.type = @"COS";
            }else {
                uploadType.type = @"OSS";
            }
            self.uploadType = uploadType;
//        //是否启用COS
//        }else if ([item.optionKey isEqualToString:@"enableossCOS"]) {
//            AccountConfigModel_uploadType *uploadType = [[AccountConfigModel_uploadType alloc] initWithString:item.optionValue error:nil];
//            uploadType.type = @"COS";
//            self.uploadType = uploadType;
//        //保修类型
        }else if ([item.optionKey isEqualToString:@"repairType"]) {
            NSMutableArray *configArray = [NSMutableArray array];
            for (NSDictionary *dict in array) {
                PublicConfigModel *model = [[PublicConfigModel alloc] initWithDictionary:dict error:nil];
                [configArray addObject:model];
            }
            AccountConfigModel_repairType *repairType = [[AccountConfigModel_repairType alloc] init];
            repairType.repairTypeArray = (NSArray<PublicConfigModel> *)configArray;
            self.repairType = repairType;
        //公司logo
        }else if ([item.optionKey isEqualToString:@"logoUrl"]) {
            CompanyLogoModel *companyModel = [[CompanyLogoModel alloc] initWithString:item.optionValue error:nil];
            self.companyLogo = companyModel;
        //VI检查自动答题
        }else if ([item.optionKey isEqualToString:@"patrolAutomaticAnswer"]) {
            self.automaticAnswer = [item.optionValue isEqualToString:@"true"];
        //地图类型
        }else if ([item.optionKey isEqualToString:@"mapType"]) {
            self.automaticAnswer = [item.optionValue isEqualToString:@"true"];
            MapTypeModel *mapModel = [[MapTypeModel alloc] initWithString:item.optionValue error:nil];
            if ([mapModel.value isEqualToString:@"googleMap"]) {
                kUser.map_Type = MapType_Google;
            }else {
                kUser.map_Type = MapType_Baidu;
            }
        //是否显示无权限菜单
        }else if ([item.optionKey isEqualToString:@"appAuthorityLock"]) {
            AuthorityLockModel *lockModel = [[AuthorityLockModel alloc] initWithString:item.optionValue error:nil];
            if ([lockModel.value isEqualToString:@"true"]) {
                kUser.appAuthorityLock = YES;
            }else {
                kUser.appAuthorityLock = NO;
            }
        }
    }
}

@end

@implementation AccountConfigModel_data



@end

@implementation PublicConfigModel



@end

/**
 第三方上传(OSS,COS)
 */
@implementation AccountConfigModel_uploadType


@end


/**
 保修费用类型
 */
@implementation AccountConfigModel_repairFeeType

@end


/**
 保修类型
 */
@implementation AccountConfigModel_repairType

@end


/**
 门店类型
 */
@implementation AccountConfigModel_storeType

@end

/**
 公司logo
 */
@implementation CompanyLogoModel

@end

/**
 地图类型
 */
@implementation MapTypeModel

@end

/**
 是否显示无权限菜单
 */
@implementation AuthorityLockModel

@end
