import { invoke } from "@tauri-apps/api/core";

import initialView from "../../fixtures/player-view/initial.json";
import type { AppInfo, DemoPackSummary, PlayerView } from "@contracts";

function isTauri(): boolean {
  return typeof window !== "undefined" && window.__TAURI_INTERNALS__ !== undefined;
}

export async function getAppInfo(): Promise<AppInfo> {
  if (!isTauri()) {
    return {
      name: "听娜娜讲故事",
      version: "0.1.0",
      contractVersion: 1
    };
  }
  return invoke<AppInfo>("get_app_info");
}

export async function getDemoPlayerView(): Promise<PlayerView> {
  if (!isTauri()) {
    return initialView as PlayerView;
  }
  return invoke<PlayerView>("get_demo_player_view");
}

export async function getDemoPackSummary(): Promise<DemoPackSummary> {
  if (!isTauri()) {
    return {
      id: "nana.demo.station",
      displayName: "天亮之前",
      revision: "0.1.0",
      characters: 1,
      worldBooks: 1,
      personas: 1,
      plotModules: 1,
      itemSpecs: 1
    };
  }
  return invoke<DemoPackSummary>("get_demo_pack_summary");
}
