const OC_WRAPPER_CLASS = "ATNativeAdWrapper";
import ATiOSJS from "./ATiOSJS"; 


interface ATiOSNativeJSInterface {
    loadNative(placementId: string, settings: string): void;
    setAdListener(listener: string): void;
    hasAdReady(placementId: string): boolean;
    checkAdStatus(placementId: string): boolean;
    showAd(placementId: string, adViewProperty: string): void;
    showAdInScenario(placementId: string, adViewProperty: string, scenario: string): void;
    removeAd(placementId: string): void;
}

const ATiOSNativeJS : ATiOSNativeJSInterface = {
    loadNative(placementId: string, settings: string): void {
        ATiOSJS.printJsLog(`ATiOSNativeJS::loadNative(${placementId}, ${settings})`);
        jsb.reflection.callStaticMethod(OC_WRAPPER_CLASS, "loadNativeWithPlacementID:extra:", placementId, settings);
    },

    setAdListener(listener: string): void {
        ATiOSJS.printJsLog(`ATiOSNativeJS::setAdListener(${listener})`);
        jsb.reflection.callStaticMethod(OC_WRAPPER_CLASS, "setDelegates:", listener);
    },
  
    hasAdReady(placementId: string): boolean {
        ATiOSJS.printJsLog(`ATiOSNativeJS::hasAdReady(${placementId})`);
        return jsb.reflection.callStaticMethod(OC_WRAPPER_CLASS, "nativeReadyForPlacementID:", placementId);
    },

    checkAdStatus(placementId: string): boolean {
        ATiOSJS.printJsLog(`ATiOSNativeJS::checkAdStatus(${placementId})`);
        return jsb.reflection.callStaticMethod(OC_WRAPPER_CLASS, "nativeCheckAdStatusForPlacementID:", placementId);
    },

    showAd(placementId: string, adViewProperty: string): void { 
        ATiOSJS.printJsLog(`ATiOSNativeJS::showAd(${placementId}, ${adViewProperty})`);
        jsb.reflection.callStaticMethod(OC_WRAPPER_CLASS, "showNativeWithPlacementID:scene:metrics:", placementId, null, adViewProperty);
    },

    showAdInScenario(placementId: string, adViewProperty: string, scenario: string): void { 
        ATiOSJS.printJsLog(`ATiOSNativeJS::showAdInScenario(${placementId}, ${adViewProperty}, ${scenario})`);
        jsb.reflection.callStaticMethod(OC_WRAPPER_CLASS, "showNativeWithPlacementID:scene:metrics:", placementId, scenario, adViewProperty);
    },

    removeAd(placementId: string): void {
        ATiOSJS.printJsLog(`ATiOSNativeJS::removeAd(${placementId})`);
        jsb.reflection.callStaticMethod(OC_WRAPPER_CLASS, "removeNativeWithPlacementID:", placementId);
    }
};

export default ATiOSNativeJS;
