import { apiFetch } from "../api/config";

export const CURRENT_APP_VERSION = "1.0.0";

export const checkForUpdates = async () => {
  try {
    const res = await apiFetch("/api/app/check-update");
    if (res.success && res.latest_version) {
      const isNewer = res.latest_version !== CURRENT_APP_VERSION;
      return {
        updateAvailable: isNewer,
        latestVersion: res.latest_version,
        currentVersion: CURRENT_APP_VERSION,
        changelog: res.changelog || [],
        apkUrl: res.apk_url || "",
        releaseDate: res.release_date || "",
      };
    }
    return { updateAvailable: false };
  } catch (err) {
    console.log("Update check error:", err);
    return { updateAvailable: false };
  }
};
