import { ContextFetchDefinition } from "../types/utility.js";
import "../types/index.js";
import { DotPaths } from "./validation-helpers.js";
import { ContextConfigSelect, CredentialReferenceApiInsert } from "../types/entities.js";
import { z } from "@hono/zod-openapi";

//#region src/context/ContextConfig.d.ts
type ExtractSchemasFromCV<CV> = { [K in keyof CV]: CV[K] extends builderFetchDefinition<infer S> ? S : never };
type InferContextFromSchemas<CZ> = { [K in keyof CZ]: CZ[K] extends z.ZodTypeAny ? z.infer<CZ[K]> : never };
type FullContext<CV> = InferContextFromSchemas<ExtractSchemasFromCV<CV>>;
type AllowedPaths<CV> = DotPaths<FullContext<CV>>;
interface HeadersSchemaBuilderOptions<R extends z.ZodTypeAny> {
  schema: R;
}
declare class HeadersSchemaBuilder<R extends z.ZodTypeAny> {
  private schema;
  constructor(options: HeadersSchemaBuilderOptions<R>);
  /** Template function for headers paths with type-safe autocomplete */
  toTemplate<P extends DotPaths<z.infer<R>>>(path: P): `{{headers.${P}}}`;
  getSchema(): R;
  getJsonSchema(): Record<string, unknown>;
}
type builderFetchDefinition<R extends z.ZodTypeAny> = {
  id: string;
  name?: string;
  trigger: 'initialization' | 'invocation';
  fetchConfig: {
    url: string;
    method?: string;
    headers?: Record<string, string>;
    body?: Record<string, unknown>;
    transform?: string;
    timeout?: number;
    requiredToFetch?: Array<string>;
  };
  responseSchema: R;
  defaultValue?: unknown;
  credentialReference?: CredentialReferenceApiInsert;
};
interface ContextConfigBuilderOptions<R extends z.ZodTypeAny | undefined = undefined, CV = Record<string, builderFetchDefinition<z.ZodTypeAny>>> {
  id: string;
  headers?: R | HeadersSchemaBuilder<R extends z.ZodTypeAny ? R : z.ZodTypeAny>;
  contextVariables?: CV;
  tenantId?: string;
  projectId?: string;
  agentId?: string;
  baseURL?: string;
}
declare class ContextConfigBuilder<R extends z.ZodTypeAny | undefined, CV extends Record<string, builderFetchDefinition<z.ZodTypeAny>>> {
  private config;
  private baseURL;
  private tenantId;
  private projectId;
  private agentId;
  constructor(options: ContextConfigBuilderOptions<R, CV>);
  /**
   * Set the context (tenantId, projectId, agentId) for this context config
   * Called by agent.setConfig() when the agent is configured
   */
  setContext(tenantId: string, projectId: string, agentId: string, baseURL: string): void;
  /**
   * Convert the builder to a plain object for database operations
   */
  toObject(): ContextConfigSelect;
  getId(): string;
  getHeadersSchema(): any;
  getContextVariables(): Record<string, ContextFetchDefinition>;
  withHeadersSchema(schema: any): this;
  /** 4) The function you ship: path autocomplete + validation, returns {{path}} */
  toTemplate<P extends AllowedPaths<CV>>(path: P): `{{${P}}}`;
  validate(): {
    valid: boolean;
    errors: string[];
  };
  init(): Promise<void>;
  private upsertContextConfig;
  private parseErrorResponse;
}
declare function contextConfig<R extends z.ZodTypeAny | undefined = undefined, CV extends Record<string, builderFetchDefinition<z.ZodTypeAny>> = Record<string, builderFetchDefinition<z.ZodTypeAny>>>(options: ContextConfigBuilderOptions<R, CV> & {
  contextVariables?: CV;
}): ContextConfigBuilder<R, CV>;
declare function headers<R extends z.ZodTypeAny>(options: HeadersSchemaBuilderOptions<R>): HeadersSchemaBuilder<R>;
declare function fetchDefinition<R extends z.ZodTypeAny>(options: builderFetchDefinition<R>): Omit<builderFetchDefinition<R>, 'credentialReference'> & {
  credentialReferenceId?: string;
};
//#endregion
export { AllowedPaths, ContextConfigBuilder, ContextConfigBuilderOptions, ExtractSchemasFromCV, HeadersSchemaBuilder, HeadersSchemaBuilderOptions, InferContextFromSchemas, builderFetchDefinition, contextConfig, fetchDefinition, headers };