import AdSystem from "../../../../system/AdSystem";
import { zgSingleton } from "../zgSingleton";
import ATBanner from "./ATBanner";
import ATInterstitial from "./ATInterstitial";
import { ATNative } from "./ATNative";
import { ATRewardVideo } from "./ATRewardVideo";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ATSDKMgr extends zgSingleton {

    /**Topon Appid */
    public static topon_android_appId = "a5f8fa5f10c661";
    /**Topon AppSecret */
    public static topon_android_appSecret = "66b742dd0e502b64d783d9c66a9d30c4";
    /**Topon 激励视频广告位 */
    public static topon_rewardVideo_placementId = "b5f8fa6673e180";
    /**Topon 插屏广告位 */
    public static topon_inter_placementId = "b5f8fa77aa5262";
    /**Topon 信息流广告位 */
    public static topon_native_placementId = "b5f8fa77aa5262";
    /**Topon 全屏插屏广告位 */
    public static topon_fullinter_placementId = "b5f8fa77aa5262";
    /**Topon 全屏插屏广告位 */
    public static topon_banner_placementId = "b5f8fa77aa5262";

    /**初始化ATSDK */
    public initATSDK() {

        cc["ATSDKMgrJS"].proxy = this;
        cc["ATSDKMgrJS"].initATJSSDK(ATSDKMgr.topon_android_appId, ATSDKMgr.topon_android_appSecret);

        //初始化激励视频广告
        ATRewardVideo.getInstance().init();
        //初始化原生广告
        ATNative.getInstance().init();
        // ATInterstitial.getInstance().init();
        // ATBanner.getInstance().init();
    }

    /**显示视频广告 */
    showVideoAd() {
        ATRewardVideo.getInstance().showAd();
    }

    /** 
     * 观看视频回调
     * @param adPlayStateType 广告播放状态类型 观看结束、播放失败、取消（关闭）
     */
    watchVideoAdCallBack(adPlayStateType: AdPlayStateType) {
        switch (adPlayStateType) {
            case AdPlayStateType.WatchEnd:
                AdSystem.getInstance().wacthAdSuccess();
                break;
            case AdPlayStateType.PlayFail:
                AdSystem.getInstance().watchAdFail();
                break;
            case AdPlayStateType.Cancel:
                AdSystem.getInstance().watchAdFail();
                break;
        }
    }

    /**显示插屏广告 */
    showInterAd() {

    }

    /** 
     * 加载原生广告
     * @param type 0 是插屏 1 是全屏
     * @param show 是否显示
     */
    loadNativeAd(type: number, show: boolean) {
        ATNative.getInstance().loadNative(type, show);
    }

    /** 销毁原生广告 */
    destroyNativeAd() {
        ATNative.getInstance().destroyNative();
    }
}

/** 广告播放状态类型 */
export enum AdPlayStateType {
    /** 观看结束 */
    WatchEnd = 0,
    /** 播放失败  */
    PlayFail = 1,
    /** 取消 */
    Cancel = 2,
}
