import { b as private_env } from './shared-server-DaWdgxVh.js';
import { v as validateAuth } from './auth-DuunT7Cg.js';
import { d as deviceTokenStore } from './device-token-store-Ct7aTeR8.js';
import { g as getProviderAvailability } from './providers-DtstoHQ0.js';
import { j as json } from './index-lhTMmBNn.js';
import { readFileSync } from 'fs';
import { join } from 'path';
import 'crypto';
import 'better-sqlite3';
import './shooter-home-4f_HkdGI.js';
import 'os';

const PKG_VERSION = (() => {
  const root = process.env.SHOOTER_PKG_ROOT || process.cwd();
  try {
    const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf-8"));
    return pkg.version || "unknown";
  } catch {
    return "unknown";
  }
})();
const GET = ({ request, url }) => {
  const wantsDetails = url.searchParams.get("details") === "true";
  if (wantsDetails) {
    const authError = validateAuth(request);
    if (authError) {
      return authError;
    }
  }
  const hasProjectId = !!private_env.FCM_PROJECT_ID?.trim();
  const hasClientEmail = !!private_env.FCM_CLIENT_EMAIL?.trim();
  const hasPrivateKey = !!private_env.FCM_PRIVATE_KEY?.trim();
  const iosDeviceCount = deviceTokenStore.listActive("ios").length;
  const androidDeviceCount = deviceTokenStore.listActive("android").length;
  const registeredDeviceCount = iosDeviceCount + androidDeviceCount;
  const checks = {
    hasApiKey: !!private_env.API_KEY?.trim(),
    hasAPNsConfig: !!(private_env.APNS_KEY_ID?.trim() && private_env.APNS_TEAM_ID?.trim() && private_env.APNS_KEY?.trim()),
    hasBundleId: !!private_env.APNS_BUNDLE_ID?.trim(),
    // Backward-compat alias: true if any device is registered OR the legacy
    // single-token env var is still set.
    hasDeviceToken: registeredDeviceCount > 0 || !!private_env.DEVICE_TOKEN?.trim() || !!private_env.ANDROID_DEVICE_TOKEN?.trim(),
    hasFCMConfig: hasProjectId && hasClientEmail && hasPrivateKey
  };
  const fcm = {
    configured: hasProjectId && hasClientEmail && hasPrivateKey,
    hasClientEmail,
    hasPrivateKey,
    hasProjectId
  };
  const configuration = {
    apnsKeyId: private_env.APNS_KEY_ID ? `${private_env.APNS_KEY_ID.substring(0, 4)}...` : "",
    bundleId: private_env.APNS_BUNDLE_ID || "",
    deviceTokenLength: private_env.DEVICE_TOKEN ? private_env.DEVICE_TOKEN.length : 0,
    fcm,
    production: private_env.APNS_PRODUCTION === "true"
  };
  const warnings = [];
  if (!checks.hasAPNsConfig || !checks.hasBundleId) {
    warnings.push("APNs not configured — iOS push notifications disabled");
  }
  if (!checks.hasDeviceToken) {
    warnings.push("No devices registered — push notifications have no target");
  }
  if (!checks.hasFCMConfig) {
    warnings.push("FCM not configured — Android push notifications disabled");
  }
  const aiProviders = getProviderAvailability(private_env);
  const hasAnyAiProvider = Object.values(aiProviders).some(Boolean);
  if (!hasAnyAiProvider) {
    warnings.push(
      'No AI provider configured — AI summaries disabled. Run "shooter setup" to configure.'
    );
  }
  const health = {
    ai: {
      activeProvider: private_env.NEUROLINK_PROVIDER ?? "auto",
      hasAnyProvider: hasAnyAiProvider,
      providers: aiProviders
    },
    checks,
    configuration,
    devices: {
      android: androidDeviceCount,
      ios: iosDeviceCount,
      total: registeredDeviceCount
    },
    environment: private_env.NODE_ENV || "development",
    status: "healthy",
    timestamp: (/* @__PURE__ */ new Date()).toISOString(),
    version: PKG_VERSION,
    warnings
  };
  if (!wantsDetails) {
    const publicWarnings = health.warnings.filter((w) => !w.includes("AI provider"));
    return json({
      status: health.status,
      timestamp: health.timestamp,
      version: health.version,
      warnings: publicWarnings
    });
  }
  return json(health);
};

export { GET };
//# sourceMappingURL=_server.ts-DUb7fbuW.js.map
