//
//  adviceInfoNetModel.m
//  Open
//
//  Created by 看看智能 on 2017/3/13.
//  Copyright © 2017年 黄江涛 . All rights reserved.
//

#import "adviceInfoNetModel.h"
#import <Reachability.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>

@implementation adviceInfoNetModel
+(id)getAdvideInfoUserId:(NSInteger)user_id andTitle_name:(int )titleName andContent_text:(NSString *)content_text andImage:(NSMutableArray*)picArr andcontact_style:(NSString*)contact_style Handle:(void (^)(postMessageModel *, NSError *))complete
{
    NSString * pathNew_1 =[IPDIZHI stringByAppendingString:@"/socialsecurity/kankan/adviceInfo"];
    NSString * pathNew1 =  [pathNew_1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
     NSDictionary *dictNew =[NSDictionary new];
    if(!contact_style){
        contact_style =@"";
    }
    
    //手机型号
    NSString* phoneModel = [[UIDevice currentDevice] model];
    
    //手机系统版本
    NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
//    NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
    if (picArr.count>0) {
        if (picArr.count < 5) {
            
        dictNew =@{
                   @"user_id":@(user_id),
                   @"advice_type":@(titleName),
                   @"content_text":[EnercryTool encryptUseDES:content_text key:DESKEY],
                   @"contact_style":contact_style,
                   @"photostr":[picArr componentsJoinedByString:@","],
                   @"frommodel":@2,
                   @"mobile_model":phoneModel,
                   @"mobile_maker":@"apple",
                   @"mobile_system":phoneVersion,
                   @"version_no":app_Version,
                   @"net_state":[adviceInfoNetModel internetStatus],
                   @"platform":@(202)
                   };
    }
    }else{
        dictNew =@{
                   @"user_id":@(user_id),
                   @"advice_type":@(titleName),
                   @"content_text":[EnercryTool encryptUseDES:content_text key:DESKEY],
                   @"contact_style":contact_style,
                   @"frommodel":@2,
                   @"mobile_model":phoneModel,
                   @"mobile_maker":@"apple",
                   @"mobile_system":phoneVersion,
                   @"version_no":app_Version,
                   @"net_state":[adviceInfoNetModel internetStatus],
                   @"platform":@(202)
                   };
        
    }
    
    
    
    
    
   
    NSLog(@"dictNew:%@",dictNew);
    return [self  POST:pathNew1 parameters:dictNew completionHandler:^(id responseObj, NSError *error) {
        NSLog(@"%@",responseObj);
        complete( [postMessageModel mj_objectWithKeyValues:responseObj],error);
        if (error) {
            NSLog(@"打印错误:%@",error);
        }
    }];


}


//获取当前网络状态
+ (NSNumber *)internetStatus {
    
    Reachability *reachability   = [Reachability reachabilityWithHostName:@"www.apple.com"];
    
    NetworkStatus internetStatus = [reachability currentReachabilityStatus];
    
    NSNumber *net = nil;
    
    switch (internetStatus) {
            
        case ReachableViaWiFi:
            
            net = [NSNumber numberWithInt:1];
            
            break;
            
            
            
        case ReachableViaWWAN:
            
            
            net = [adviceInfoNetModel getNetType];   //判断具体类型
            
            break;
            
            
            
        case NotReachable:
            
            net = [NSNumber numberWithInt:99];
            
            
            
        default:
            
            break;
            
    }
    
    
    
    return net;
    
}


+ (NSNumber *)getNetType

{
    
    CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
    
    NSNumber *netconnType = nil;
    
    NSString *currentStatus = info.currentRadioAccessTechnology;
   if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyWCDMA"]){
        
        netconnType = [NSNumber numberWithInt:3];
        
    }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMA1x"]){
        
        netconnType = [NSNumber numberWithInt:2];
        
    }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORev0"]){
        
        netconnType = [NSNumber numberWithInt:3];
        
    }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevA"]){
        
        netconnType = [NSNumber numberWithInt:3];
        
    }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevB"]){
        
        netconnType = [NSNumber numberWithInt:3];
        
    }else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyLTE"]){
        
       netconnType = [NSNumber numberWithInt:4];
        
    }else{
        netconnType = [NSNumber numberWithInt:98];
    }
    
    return netconnType;
    
}
@end
