/**
 * @description 广告数据
 * @author 邹勇
 */
export class AdData {

    public placementId = '';
    public adunit_format = '';
    public network_type = '';
    public network_placement_id = '';
    public network_firm_id = '';
    public adsource_id = '';
    public adsource_index = '';
    public adsource_price = '100';
    public adsource_isheaderbidding = '';
    public publisher_revenue = '';
    public precision = '';
    public ecpm_level = '';

    /** 广告类型（1:激励视频、2:插屏、3:信息流） */
    public adType: number = 1;

    /** 视频类型 */
    public ad_subType: AdFun;

    private datas: any[];


    public init() {
        this.datas = [, gData.reward, gData.reward, gData.reward, gData.turnable, gData.sign, gData.blessingBag];
    }


    public updateData(placementId, data) {
        mk.console.logSingle("updateADData:" + placementId, data);
        this.placementId = placementId;
        this.adunit_format = data.adunit_format;
        this.network_type = data.network_type;
        this.network_placement_id = data.network_placement_id;
        this.network_firm_id = data.network_firm_id;
        this.adsource_id = data.adsource_id;
        this.adsource_index = data.adsource_index;
        this.adsource_price = data.adsource_price;
        this.adsource_isheaderbidding = data.adsource_isheaderbidding;
        this.publisher_revenue = data.publisher_revenue;
        this.precision = data.precision;
        this.ecpm_level = data.ecpm_level;
    }


    public async watchVideo(type: AdFun) {
        this.ad_subType = type;
        let data = {
            "imei": gData.appData.machineInfo.imei,
            "idfa": gData.appData.machineInfo.idfa,
            "oaid": gData.appData.machineInfo.oaid,
            "uin": gData.loginData.uin,
            "version": gData.appData.appVersion,
            "tf_channel": gData.appData.tfChannel,
            "destoon_ad_place": this.placementId,
            "ad_type": 1,
            "adunit_format": this.adunit_format,
            "network_type": this.network_type,
            "network_placement_id": this.network_placement_id,
            "network_firm_id": this.network_firm_id,
            "adsource_id": this.adsource_id,
            "adsource_index": this.adsource_index,
            "adsource_price": this.adsource_price,
            "adsource_isheaderbidding": this.adsource_isheaderbidding,
            "publisher_revenue": this.publisher_revenue,
            "precision_ecpm": this.precision,
            "ecpm_level": this.ecpm_level,
            "cfg_version": gData.appData.version,
            "adsource_ecpm": gData.gameData.adShowConfig.average_ecpm,
            "ad_sbuType": this.ad_subType,
        }
        mk.console.logSingle("updateVideoData:",data);
        
        let response = await mk.http.sendData('updateVideo', data);
        if (response.errcode != 0) {
            return;
        }

        if (this.datas[this.ad_subType]) {
            this.datas[this.ad_subType].setAdData(response.data);
        }
    }

}

/**
 * 看视频类型
 */
export enum AdFun {
    bubble = 1,         //气泡视频
    checkpoint = 2,     //关卡消除视频
    settlement = 3,     //关卡通关视频
    turntable = 4,      //转盘视频
    sign = 5,           //签到视频
    bigCash = 6,        //福袋视频
}