import { FrameworkError } from './errors.cjs';
import { PlainObject, ObjectLike } from './internals/types.cjs';
import { Serializable } from './internals/serializable.cjs';
import { ZodType, z } from 'zod';
import { SchemaObject } from 'ajv';
import './internals/helpers/guards.cjs';

/**
 * Copyright 2025 IBM Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

type PostInfer<T> = T extends PlainObject ? {
    [K in keyof T]: T[K] extends Date ? string : T[K];
} : T;
type InferValue<T> = T extends ZodType<infer A> ? PostInfer<A> : never;
type PromptTemplateRenderFn<K extends ZodType> = (this: InferValue<K>) => any;
type PromptTemplateRenderInput<T extends ZodType, T2 extends z.input<T> = z.input<T>> = {
    [K in Extract<keyof T2, string>]: T2[K] | PromptTemplateRenderFn<T> | undefined;
};
interface PromptTemplateInput<T extends ZodType> {
    template: string;
    customTags?: [string, string];
    escape?: boolean;
    schema: SchemaObject;
    defaults?: Partial<InferValue<T>>;
    functions?: Record<string, PromptTemplateRenderFn<T>>;
}
type PromptTemplateConstructor<T extends ZodType, N> = N extends ZodType ? Omit<PromptTemplateInput<N>, "schema" | "functions" | "defaults"> & {
    schema: N;
    functions?: Record<string, PromptTemplateRenderFn<N | T>>;
    defaults?: Partial<InferValue<N | T>>;
} : Omit<PromptTemplateInput<T>, "schema"> & {
    schema: T | SchemaObject;
};
type Customizer<T extends ZodType, N> = ((config: Required<PromptTemplateInput<T>>) => PromptTemplateConstructor<T, N>) | ((config: Required<PromptTemplateInput<T>>) => void);
declare class PromptTemplateError<T extends ZodType> extends FrameworkError {
    template: PromptTemplate<T>;
    constructor(message: string, template: PromptTemplate<T>, context?: ObjectLike);
}
declare class ValidationPromptTemplateError<T extends ZodType> extends PromptTemplateError<T> {
}
declare class PromptTemplate<T extends ZodType> extends Serializable {
    protected config: Required<PromptTemplateInput<T>>;
    static functions: {
        trim: () => (text: string, render: (value: string) => string) => string;
    };
    constructor(config: Omit<PromptTemplateInput<T>, "schema"> & {
        schema: T | SchemaObject;
    });
    validateInput(input: unknown): asserts input is T;
    fork(customizer: Customizer<T, SchemaObject>): PromptTemplate<T>;
    fork<R extends ZodType>(customizer: Customizer<T, R>): PromptTemplate<R>;
    render(input: PromptTemplateRenderInput<T>): string;
    loadSnapshot(data: ReturnType<typeof this.createSnapshot>): void;
    createSnapshot(): {
        config: Required<PromptTemplateInput<T>>;
    };
}
declare namespace PromptTemplate {
    type infer<T> = PromptTemplate<ZodType<T>>;
}

export { PromptTemplate, PromptTemplateError, type PromptTemplateInput, type PromptTemplateRenderFn, type PromptTemplateRenderInput, ValidationPromptTemplateError };
