//
//  XXGAppLovinManager.m
//  XXGPlayKitOS
//
//  Created by apple on 2025/5/8.
//

#import "XXGAppLovinManager.h"
#import "XXGPlayKitConfig.h"
#import "NSObject+XXGPerformSelector.h"
#import "ZBObjectiveCBeaver.h"
#import "XXGNetworkList.h"

@implementation XXGAppLovinManager

+ (id)xxpk_middlewareClass {
    Class class = NSClassFromString(__data_core.xxpk_middleware_applovin);
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        ZBLogInfo(__data_core.xxpk_log_manager_applovin,class?[NSString stringWithFormat:__data_core.xxpk_manager_status_exist_version,[class xxpk_performSelector:@selector(xxpk_version)]]:__data_core.xxpk_manager_status_not_exist);
    });
    if (class) {
        return [class xxpk_performSelector:@selector(shared)];
    }
    return nil;
}

+ (void)xxpk_initApplovinSDKWithKey:(NSString *)xxpk_maxkey xxpk_rewardedadid:(NSString *)xxpk_rewardedadid xxpk_interstitialadid:(NSString *)xxpk_interstitialadid xxpk_testDevices:(NSArray *)xxpk_testDevices {
    if ([self xxpk_middlewareClass]) {
        // 设置广告事件回调
        [[self xxpk_middlewareClass] xxpk_performSelector:@selector(xxpk_setAdEventCallback:) withObject:^(NSDictionary *adInfo) {
            // 调用网络层上报
            [[XXGNetworkList xxpk_defaultNetwork] xxpk_networkReportAdvInfo:adInfo];
        }];

        // 初始化 SDK
        [[self xxpk_middlewareClass] xxpk_performSelector:@selector(xxpk_initApplovinSDKWithKey:xxpk_rewardedadid:xxpk_interstitialadid:xxpk_testDevices:) withObject:xxpk_maxkey withObject:xxpk_rewardedadid withObject:xxpk_interstitialadid withObject:xxpk_testDevices];
    }
}

+ (void)xxpk_showRewardedAdForCustomData:(nullable NSString *)customData complate:(void(^)(BOOL result))complate {
    if ([self xxpk_middlewareClass]) {
        [[self xxpk_middlewareClass] xxpk_performSelector:@selector(xxpk_showRewardedAdForCustomData:complate:) withObject:customData withObject:complate];
    }else {
        complate(NO);
    }
}


+ (void)xxpk_showRewardedAdForCustomData:(nullable NSString *)customData complateAdJson:(void(^)(BOOL result, NSDictionary *adJson))complateAdJson {
    if ([self xxpk_middlewareClass]) {
        [[self xxpk_middlewareClass] xxpk_performSelector:@selector(xxpk_showRewardedAdForCustomData:complateAdJson:) withObject:customData withObject:complateAdJson];
    }else {
        complateAdJson(NO,nil);
    }
}

+ (void)xxpk_showInterstitialAdForCustomData:(nullable NSString *)customData complate:(void(^)(BOOL result))complate {
    if ([self xxpk_middlewareClass]) {
        [[self xxpk_middlewareClass] xxpk_performSelector:@selector(xxpk_showInterstitialAdForCustomData:complate:) withObject:customData withObject:complate];
    } else {
        complate(NO);
    }
}

+ (void)xxpk_showInterstitialAdForCustomData:(nullable NSString *)customData complateAdJson:(void(^)(BOOL result, NSDictionary *adJson))complateAdJson {
    if ([self xxpk_middlewareClass]) {
        [[self xxpk_middlewareClass] xxpk_performSelector:@selector(xxpk_showInterstitialAdForCustomData:complateAdJson:) withObject:customData withObject:complateAdJson];
    } else {
        complateAdJson(NO, nil);
    }
}

@end
