import { Data } from "../../../mk/data/Data";
import { AdFun } from "../AdData";
import { GameProp } from "../GameData";

interface TurntableItem {
    id: string,
    type: string,
}

/**
 * @description 转盘数据
 * @author 邹勇
 */
export class TurnableData extends Data {

    public requestFinish: boolean = false;

    public leftTimes: number = 0;
    public config: TurntableItem[];

    public init() {
        this.config = gData.gameData.configs.TurntableCfg;
        this.leftTimes = gData.gameData.gameData.turntableTimes == null ? 0 : gData.gameData.gameData.turntableTimes;
    }

    public async requestData() {
        let response = await mk.http.sendData('initialTurntable', {});
        if (response.errcode != 0) {
            return;
        }
        this.leftTimes = response.data.turntableTimes;
        this.requestFinish = true;
    }

    public setAdData(data) {
        super.setAdData(data);

        this.leftTimes = this.leftTimes < 1 ? 0 : this.leftTimes - 1;
        gData.gameData.setProp(GameProp.turnable_leftTimes, this.leftTimes);
    }


    public draw() {
        mk.ad.watchAd((success: boolean) => {
            mk.console.log("watchAD:" + success);
            if (success) {
                gData.adData.watchVideo(AdFun.turntable);
            }
        });
    }
}