// 广告模块
import Gamecfg from "../../common/gameCfg";
import { gameMethod } from "../../common/gameMethod";
import { Kind11Success, Kind11SuccessPram, TaobaoKind11Rwd, TaobaoKind11RwdPram } from "../../common/Xyc";
// import { Kind11Success, Kind11SuccessPram, Kind11Xiadan, Kind11XiadanPram } from "../../common/Xyc";
import { SevBack } from "../../common/Xys";
import Config from "../../Config";
import UIHelp from "../../logic/ui/UIHelp";
import HttpRequest from "../../network/HttpRequest";
import ThinkingDataMgr from "../../utils/ThinkingDataMgr";
import { AD_VIDEO_STRING, HdBanBenFuLiCard, HdPriCardKey, PlatformType } from "../const/TypeConst";
import GameDataCenter from "../GameDataCenter";
import IDataModel from "../../frameWork/model/IDataModel";

export default class AdVideoModel extends IDataModel {
    // private curAd: Kind11XiadanPram
    private seeSuccCallback: (isSucc: boolean, sevBack?: SevBack) => void
    private adOrderId: string

    // 是否开启广告功能
    openAD: boolean = false
    constructor() {
        super('adVideo');
    }
    doSevback(result: SevBack): void {

    }
    setAdOpen() {
        // 无配置,走正常开启广告入口
        if (gameMethod.isEmpty(Config.adVideo)) {
            this.openAD = true
        }
        this.openAD = Config.adVideo == "1"
    }
    /**
     * 下单看广告
     * @param kid   标识
     * @param hdcid 标识    
     * @param dc 档次ID
     * @param callback 看完广告的回调
     */
    sendSeeVideo(kid: string, order11Id: string, adkey: string, callback: (isSucc: boolean, sevBack?: SevBack) => void = () => { }) {

        this.seeSuccCallback = callback

        // 开始看广告
        this.adOrderId = order11Id

        // 判断是否免广告(福利宝箱不可跳过)
        if (this.isAdFree(adkey)) {
            console.warn("免广告,直接领取奖励")
            this.onXiadanSucc()
        } else {
            console.warn("要看广告,开始看")
            //数数上报
            let kidStr = gameMethod.isEmpty(AD_VIDEO_STRING[kid]) ? kid : AD_VIDEO_STRING[kid]
            let properties = {
                "ad_platform": "微信小游戏",
                "ad_id": adkey,
                "ad_type": "激励视频",
                "ad_placement_name": "home_feed",
                "ad_placement_id": order11Id,
                "current_page": kidStr,
                // "ad_ecpm": 0,
                "ad_app_name": "未知"
            }
            ThinkingDataMgr.TDTrack("ad_click", properties)
            GameDataCenter.plat.instance.showRewardAd(adkey, kidStr, order11Id)
        }
    }
    // 下单成功通知看广告
    onXiadanSucc() {
        let param: Kind11SuccessPram = {
            order11Id: this.adOrderId
        }
        // 通知一下
        this.send(Kind11Success.url, param, (result: SevBack) => {
            if (result.type == 1) {
                this.seeSuccCallback(true, result);
            }
        })
    }

    // 淘宝 下单成功通知看广告
    onTaoBaoXiadanSucc() {
        let param: TaobaoKind11RwdPram = {

        }
        // 通知一下
        this.send(TaobaoKind11Rwd.url, param, (result: SevBack) => {
            if (result.type == 1) {
                this.seeSuccCallback(true)
            }
        })
    }

    // 是否可以跳过广告
    isAdFree(adUnitId: string): boolean {
        if (GameDataCenter.hdPriCard.isPriCardEffect(HdPriCardKey.adver) || gameMethod.isEmpty(adUnitId)) {
            return true
        }
        return false
    }
}