import { AgentsManageDatabaseClient, CredentialStoreRegistry, ResolvedRef, ServerConfig } from "@inkeep/agents-core";
import { createAuth } from "@inkeep/agents-core/auth";

//#region src/types/app.d.ts
type AuthInstance = ReturnType<typeof createAuth>;
interface CommonSandboxConfig {
  runtime: 'node22' | 'typescript';
  timeout?: number;
  vcpus?: number;
}
interface NativeSandboxConfig extends CommonSandboxConfig {
  provider: 'native';
}
interface VercelSandboxConfig extends CommonSandboxConfig {
  provider: 'vercel';
  teamId: string;
  projectId: string;
  token: string;
}
type SandboxConfig = NativeSandboxConfig | VercelSandboxConfig;
type BaseAppVariables = {
  requestId: string;
  userId?: string;
  userEmail?: string;
  tenantId?: string;
  tenantRole?: string;
  projectId?: string;
};
type AppVariables = BaseAppVariables & {
  serverConfig: ServerConfig;
  credentialStores: CredentialStoreRegistry;
  auth: AuthInstance;
  user: AuthInstance['$Infer']['Session']['user'] | null;
  session: AuthInstance['$Infer']['Session']['session'] | null;
  sandboxConfig?: SandboxConfig;
  requestBody?: unknown;
};
type ManageAppVariables = AppVariables & {
  db: AgentsManageDatabaseClient;
  auth: AuthInstance;
  resolvedRef: ResolvedRef;
  /** Cached by projectFull middleware to avoid duplicate DB lookup for PUT upsert */
  isProjectCreate?: boolean;
};
type AppConfig = {
  serverConfig: ServerConfig;
  credentialStores: CredentialStoreRegistry;
  auth: AuthInstance;
  sandboxConfig?: SandboxConfig;
};
/**
 * Minimal app variables for public/OAuth routes
 * Does not include authentication variables
 */
type PublicAppVariables = {
  credentialStores: CredentialStoreRegistry;
};
/**
 * Minimal app variables for OAuth routes with server config
 */
type PublicAppVariablesWithServerConfig = {
  db: AgentsManageDatabaseClient;
  serverConfig: ServerConfig;
  credentialStores: CredentialStoreRegistry;
};
//#endregion
export { AppConfig, AppVariables, ManageAppVariables, NativeSandboxConfig, PublicAppVariables, PublicAppVariablesWithServerConfig, SandboxConfig, VercelSandboxConfig };