import type { AuthAdapter, HeaderBuilder, HttpSuiteConfig } from "../index";

export interface LocalDatabaseConfig {
  provider: "local";
  image?: string;
  password?: string;
  reset?: boolean;
  template?: {
    inputs?: string[];
  };
  user?: string;
}

export interface LifecycleConfig {
  cmd: string;
  cwd?: string;
  testkitCmd?: string;
  testkitCwd?: string;
}

export interface ServiceConfig {
  database?: LocalDatabaseConfig;
  databaseFrom?: string;
  dependsOn?: string[];
  discovery?: {
    roots?: string[];
  };
  envFile?: string;
  envFiles?: string[];
  local?: {
    baseUrl: string;
    cwd?: string;
    env?: Record<string, string>;
    port?: number;
    readyTimeoutMs?: number;
    readyUrl: string;
    start: string;
  };
  migrate?: LifecycleConfig;
  seed?: LifecycleConfig;
}

export interface TestkitSetup {
  profiles?: {
    http?: Record<string, HttpSuiteConfig>;
  };
  services?: Record<string, ServiceConfig>;
  telemetry?: {
    enabled?: boolean;
    endpoint?: string;
    timeoutMs?: number;
    tokenEnv?: string;
  };
}

export declare function defineTestkitSetup<T extends TestkitSetup>(setup: T): T;
export declare function defineHttpProfile<T extends HttpSuiteConfig>(profile: T): T;
export declare function service<T extends ServiceConfig>(config: T): T;
export declare function localDatabase(options?: Omit<LocalDatabaseConfig, "provider">): LocalDatabaseConfig;
export declare function lifecycle(cmd: string, options?: Omit<LifecycleConfig, "cmd">): LifecycleConfig;
export declare function goService(options: ServiceConfig["local"] & {
  command?: string;
  entrypoint?: string;
  envFiles?: string[];
  readyPath?: string;
}): ServiceConfig;
export declare function nextService(options: ServiceConfig["local"] & {
  envFiles?: string[];
}): ServiceConfig;
export declare function tsxService(options: ServiceConfig["local"] & {
  entry?: string;
  envFiles?: string[];
  readyPath?: string;
}): ServiceConfig;
export declare function clerkSessionProfile(options?: {
  apiBase?: string;
  needsAuth?: boolean;
  secretKeyEnv?: string;
}): HttpSuiteConfig;
export declare function jsonSessionProfile(options?: {
  body?: (context: { env: Record<string, string> }) => unknown;
  cookieName?: string;
  headers?: Record<string, string>;
  loginPath?: string;
  passwordEnv?: string;
  successStatus?: number;
  usernameEnv?: string;
}): HttpSuiteConfig;

export declare function registerRepoSetup(setup: unknown): void;
export declare function getRepoSetup(): unknown;
export declare function clearRepoSetup(): void;
export declare function registerRuntimeContext(context: unknown): void;
export declare function getRuntimeContext(): unknown;
export declare function clearRuntimeContext(): void;
export declare const runtimeHttp: {
  del(url: string, body?: unknown, params?: unknown): unknown;
  file(data: unknown, filename?: string, contentType?: string): unknown;
  get(url: string, params?: unknown): unknown;
  patch(url: string, body?: unknown, params?: unknown): unknown;
  post(url: string, body?: unknown, params?: unknown): unknown;
  put(url: string, body?: unknown, params?: unknown): unknown;
};
export declare function runtimeJson<T = unknown>(response: { body: string }): T;
