#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"

@interface AppDelegate()<FlutterStreamHandler>
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];
    [self flutterMethod];
  // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}


- (void)flutterMethod {
    FlutterViewController* controller =
    (FlutterViewController*)self.window.rootViewController;
   
    FlutterMethodChannel* buryChannel = [FlutterMethodChannel
                                         methodChannelWithName:@"flutter_channel"
                                         binaryMessenger:controller];
    
    FlutterEventChannel* flutterEvent=[FlutterEventChannel
                                          eventChannelWithName:@"flutter_channel_event" binaryMessenger:controller];
       
       [flutterEvent setStreamHandler:self];
    
    [buryChannel setMethodCallHandler:^(FlutterMethodCall* call,
                                        FlutterResult result) {
        NSLog(@" ME %@   argue  %@",call.method,call.arguments);
        if([call.method isEqualToString:@"FLUTTER_TO_H5"]){
            NSLog(@"FLUTTER_TO_H5");
        }else if([call.method isEqualToString:@"FLUTTER_TO_NATIVE"]){
            NSLog(@"FLUTTER_TO_NATIVE");
        }else if ([call.method isEqualToString:@"FLUTTER_BURIED"]){
            NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
            //APPInfo
            [dict setObject:@"alpha" forKey:@"app_name"];
            [dict setObject:@"app_version_name" forKey:@"app_version_name"];
            [dict setObject:@"channel" forKey:@"channel"];
            [dict setObject:@"" forKey:@"current_city_id"];
            [dict setObject:[[NSMutableDictionary alloc] initWithCapacity:0] forKey:@"user_type"];
            [dict setObject:@"" forKey:@"grey_type"];
            
            //DeviceInfo
            [dict setObject:@"device_id" forKey:@"device_id"];
            [dict setObject:@"Apple" forKey:@"manufacturer"];
            [dict setObject:@"lng" forKey:@"lng"];
            [dict setObject:@"lat" forKey:@"lat"];
            [dict setObject:@"is_WiFi" forKey:@"is_WiFi"];
            [dict setObject:@"ip" forKey:@"ip"];
            [dict setObject:@"model" forKey:@"model"];
            [dict setObject:@"sys_version" forKey:@"sys_version"];
            [dict setObject:@"Apple" forKey:@"lng"];
            [dict setObject:@"idfa" forKey:@"idfa"];
            [dict setObject:@"idfv" forKey:@"idfv"];
            
            [dict setObject:@"user_id" forKey:@"user_id"];
            [dict setObject:@"" forKey:@"app_session_id"];
            [dict setObject:@"create_at" forKey:@"create_at"];
            [dict setObject:@"110" forKey:@"version"];
            result(dict);
        }else if([call.method isEqualToString:@"GET_NET_TYPE"]){
            result(@"wifi");
        }else if([call.method isEqualToString:@"INIT_PARAMS"]){
            NSMutableDictionary * map=[[NSMutableDictionary alloc] init];
            NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
            [dict setObject:@"sessionid=9odo0sov71x66ke9dlphibnq9i9gduxj;_gtid=3fbe9b78d2cb11e98bc1525400e82fab5270; _gm_token=db88861568285036" forKey:@"Cookie"];
            [dict setObject:@"debug" forKey:@"buildConfig"];
                //HERE
//            [dict setObject:@"172.30.9.84:6666" forKey:@"proxy"];
            result(dict);
        }else if([call.method isEqualToString:@"UPLOAD_IMG"]){
            result(@"2019/10/17/1156/44dbb13ac6d9");
        }
    }];
}

#pragma mark - FlutterStreamHandler
- (FlutterError* _Nullable)onListenWithArguments:(id _Nullable)arguments
                                       eventSink:(FlutterEventSink)eventSink{
    self._flutterEvent = eventSink;
    return nil;
}
 
- (FlutterError* _Nullable)onCancelWithArguments:(id _Nullable)arguments {
    return nil;
}

@end
