import { EventDispatcher } from "../../engines/events/EventDispatcher";
import IInitiator from "../../engines/initiators/IInitiator";
import InitiatorEvent from "../../engines/initiators/InitiatorEvent";
import { LiangLiangSDK } from "../../platforms/libs/liangliangSDK";
import { NotPlatform } from "../../platforms/NotPlatform";
import { PlatformManager } from "../../platforms/PlatformManager";
import { WeChatPlatform } from "../../platforms/weChat/WeChatPlatform";
import GameModel from "../models/GameModel";




export default class AdsInitiator extends EventDispatcher implements IInitiator{

    Start(): void {
        if(window["wx"]){
            PlatformManager.init(new WeChatPlatform());
            PlatformManager.login(()=>{
                GameModel.single.gameName="LLStarRacing";
                GameModel.single.userId=LiangLiangSDK.userID;
                this.onComplete();
            },()=>{});
        }else{
            PlatformManager.init(new NotPlatform());
            PlatformManager.login(()=>{
                GameModel.single.gameName="LLStarRacing";
                GameModel.single.userId="Greg";
                this.onComplete();
            },()=>{});
        }
    }
    
    private onComplete():void{
        GameModel.single.ReadByLocal();
        this.DispatchEvent(InitiatorEvent.EVENT_COMPLETE);
    }

    Destroy(): void {

    }

    GetName(): string {
        return "AdsInitiator";
    }
}