import {
  getConfig
} from "./chunk-2MAQ6JFL.js";

// src/providers/registry.ts
var PROVIDERS = {
  sprites: async () => (await import("./providers/sprites.js")).spritesProvider,
  docker: async () => (await import("./providers/docker.js")).dockerProvider,
  "apple-container": async () => (await import("./providers/apple-container.js")).appleProvider,
  "apple-firecracker": async () => (await import("./providers/apple-firecracker.js")).mvmProvider,
  podman: async () => (await import("./providers/podman.js")).podmanProvider,
  e2b: async () => (await import("./providers/e2b.js")).e2bProvider,
  vercel: async () => (await import("./providers/vercel.js")).vercelProvider,
  daytona: async () => (await import("./providers/daytona.js")).daytonaProvider,
  fly: async () => (await import("./providers/fly.js")).flyProvider,
  modal: async () => (await import("./providers/modal.js")).modalProvider,
  mvm: async () => (await import("./providers/apple-firecracker.js")).mvmProvider,
  anthropic: async () => (await import("./providers/anthropic.js")).anthropicProvider,
  cloudflare: async () => (await import("./providers/cloudflare.js")).cloudflareProvider
};
async function resolveContainerProvider(providerName) {
  if (!providerName) throw new Error("No container provider specified \u2014 set provider in the environment config");
  const key = providerName;
  const loader = PROVIDERS[key];
  if (!loader) throw new Error(`Unknown provider: "${key}". Available: ${Object.keys(PROVIDERS).join(", ")}`);
  return loader();
}
async function resolveProvider(opts) {
  const result = await tryResolveProvider(opts);
  if (!result) {
    throw new Error(
      "No container provider configured. Set DEFAULT_PROVIDER env var, use gateway serve --provider <name>, or gateway worker --provider <name>."
    );
  }
  return result;
}
async function tryResolveProvider(opts) {
  if (opts?.override) {
    return resolveContainerProvider(opts.override);
  }
  if (opts?.envConfigProvider) {
    return resolveContainerProvider(opts.envConfigProvider);
  }
  const cfg = getConfig();
  if (cfg.defaultProvider) {
    return resolveContainerProvider(cfg.defaultProvider);
  }
  return null;
}
function resolveProviderName(opts) {
  if (opts?.override) return opts.override;
  if (opts?.envConfigProvider) return opts.envConfigProvider;
  const cfg = getConfig();
  if (cfg.defaultProvider) return cfg.defaultProvider;
  return "unknown";
}

export {
  resolveContainerProvider,
  resolveProvider,
  tryResolveProvider,
  resolveProviderName
};
