/**
 * 多渠道点击广告
 * 1每个渠道,按天保存数据
 * 2点击渠道广告时,需要做一个渠道标记.
 * 2
 */

var ADmultiTool = new class {
    

    constructor() {
    }

    //每次调用,会把当前单价,累计
    public saveEcpm(channel: string): AdData {
        let data: AdData = this.getAdData(channel)
        let ecpm = this.getEcpm()
        data.addData(ecpm)
        data.price = ecpm
        this.setAdData(channel, data)

        return data
    }

    getAdData(channel: string): AdData {
        let data = new AdData(ZFile.getLocalJson(this.keyEcpm(channel), new AdData(null)))
        data.channel = channel
        return data
    }

    setAdData(channel: string, data: AdData) {
        if (channel && data) {
            ZFile.setLocalJson(this.keyEcpm(channel), data)
        }
    }

    private getEcpm(): number {
        let val = "0"
        if (CC_JSB && cc.sys.os == cc.sys.OS_ANDROID && jsb.reflection) {
            val = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "getEcpm", "()Ljava/lang/String;")
        }
        return Number(val)
    }

    private keyEcpm(channel: string): string {
        return "ecpm" + channel
    }

}

window["ADmultiTool"] = ADmultiTool
