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

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

  return {
    platform: "google",

    init() {},

    onResourcesLoaded() {},

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

    onGameEnd() {
      if (ended) return;
      ended = true;
    },

    openStore() {
      if (typeof window.ExitApi !== "undefined" && window.ExitApi.exit) {
        window.ExitApi.exit();
      } else {
        // 非 Google 广告环境下的 fallback（如本地调试）
        window.open(getStoreUrl(), "_blank");
      }
    },

    shouldUseCustomLoading() {
      return true;
    },

    shouldShowAdBadge() {
      return true;
    },
  };
}

export const adPlatform = createGoogleAdapter();
