//
//  SDKManager.c
//  Unity-iPhone
//
//

#import "SDKManager.h"
#import <TDKEngineBaseAdapter/TDKEngineBaseAdapter.h>
#import "UnityAppController.h"
#import "UnityInterface.h"
#import "UnityAppController.h"
#import "UnityAppController+ViewHandling.h"
#import "UnityAppController+Rendering.h"
#import "iPhone_Sensors.h"
#import "UnityInterface.h"
#include <objc/runtime.h>

@implementation SDKManager : UnityAppController

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
    [super application:application didFinishLaunchingWithOptions:launchOptions];
    [TDKEngineBaseAdapter application:application didFinishLaunchingWithOptions:launchOptions];
    return YES;
}

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
#if UNITY_USES_REMOTE_NOTIFICATIONS
    [super application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
#endif
    [TDKEngineBaseAdapter application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
#if UNITY_USES_REMOTE_NOTIFICATIONS
    [super application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:handler];
#endif
    [TDKEngineBaseAdapter application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:handler];
}

- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url options:(NSDictionary<NSString*, id>*)options
{
    [super application:application openURL:url options:options];
    [TDKEngineBaseAdapter application:application openURL:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey] annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
    [TDKEngineBaseAdapter application:application openURL:url options:options];
    return YES;
}

-(BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
    BOOL result = [super application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
    [TDKEngineBaseAdapter application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
    return result;
}

- (void)applicationDidBecomeActive:(UIApplication*)application
{
    [super applicationDidBecomeActive:application];
    [TDKEngineBaseAdapter applicationDidBecomeActive:application];
}

-(void)applicationWillTerminate:(UIApplication *)application{
    [super applicationWillTerminate:application];
    [TDKEngineBaseAdapter applicationWillTerminate:application];
}

@end
IMPL_APP_CONTROLLER_SUBCLASS(SDKManager);
