import { AdPlatformAdapter } from "../types";

export function createPlayturboAdapter(): AdPlatformAdapter {
  let ready = false;
  let started = false;
  let ended = false;

  const adapter: AdPlatformAdapter = {
    platform: "playturbo",

    init() {
      window.gameStart = () => adapter.onGameStart();
      window.gameClose = () => {};
    },

    onResourcesLoaded() {
      if (ready) return;
      ready = true;
      window.gameReady?.();
    },

    onGameStart() {
      if (started) return;
      started = true;
    },

    onGameEnd() {
      if (ended) return;
      ended = true;
      window.gameEnd?.();
    },

    openStore() {
      window.install?.();
    },

    shouldUseCustomLoading() {
      return false;
    },

    shouldShowAdBadge() {
      return true;
    },
  };

  return adapter;
}

export const adPlatform = createPlayturboAdapter();
