import { OpenApiZodAny, extendApi } from '@anatine/zod-openapi';
export { OpenApiZodAny } from '@anatine/zod-openapi';
import { SchemaObject } from 'openapi3-ts';

type SplitPath<P extends string> = P extends `${infer X}/${infer Y}` ? [X, ...SplitPath<Y>] : [P];
type KeepPathVar<P extends string> = P extends `{${infer Var}}` ? [Var] : [];
type Cast<A, B> = A extends B ? A : B;
type FilterPathVar<P extends string[]> = P extends [`${infer Head}`] ? KeepPathVar<Head> : P extends [infer Head, ...infer Tail] ? [...KeepPathVar<Cast<Head, string>>, ...FilterPathVar<Cast<Tail, string[]>>] : [];
type ToUnion<P extends string[]> = P[number];
type PathParams<P extends string> = ToUnion<FilterPathVar<SplitPath<P>>>;

type SchemaType = 'zod-schema' | 'json-schema';
type SchemaOfType<T extends SchemaType> = T extends 'zod-schema' ? OpenApiZodAny : SchemaObject;
type State<SchemaName extends string, DefaultParameterName extends string, SectionName extends string> = {
    metadata: Metadata;
    refs: RefMap;
    defaultParameters?: {
        [name in DefaultParameterName]: Parameter<'json-schema'>;
    };
    sections: {
        name: SectionName;
        title: string;
        description: string;
        schema?: string;
        operations: string[];
    }[];
    schemas: Record<SchemaName, {
        schema: SchemaObject;
        section: SectionName;
    }>;
    errors?: ApiError[];
    operations: {
        [name: string]: Operation<DefaultParameterName, SectionName, string, 'json-schema'>;
    };
};
type ApiError = {
    status: 400 | 401 | 402 | 403 | 404 | 405 | 408 | 409 | 413 | 415 | 429 | 500 | 501 | 502 | 503 | 504;
    type: string;
    description: string;
};
type Metadata = {
    server: string;
    title: string;
    version: string;
    description: string;
    prefix?: string;
};
type RefMap = {
    [name in ComponentType]: {
        [name: string]: boolean;
    };
};
type BaseParameter = {
    description: string;
};
type PathParameter = BaseParameter & {
    type: 'string';
    in: 'path';
    enum?: string[];
};
type StandardParameter = BaseParameter & {
    type: 'string';
    required?: boolean;
    enum?: string[] | readonly string[];
    in: 'query' | 'header' | 'cookie';
};
type QueryParameterStringArray = BaseParameter & {
    type: 'string[]';
    required?: boolean;
    enum?: string[];
    in: 'query';
};
type QueryParameterObject<S extends SchemaType = 'zod-schema'> = BaseParameter & {
    type: 'object';
    in: 'query';
    required?: boolean;
    schema: SchemaOfType<S>;
};
type Parameter<S extends SchemaType = 'zod-schema'> = StandardParameter | PathParameter | QueryParameterObject<S> | QueryParameterStringArray;
declare const operationsWithBodyMethod: readonly ["post", "put", "patch"];
type OperationsWithBodyMethod = (typeof operationsWithBodyMethod)[number];
type OperationWithBodyProps<DefaultParameterName extends string, SectionName extends string, Path extends string = string, S extends SchemaType = 'zod-schema'> = {
    method: OperationsWithBodyMethod;
    requestBody: {
        description: string;
        schema: SchemaOfType<S>;
    };
} & BaseOperationProps<DefaultParameterName, SectionName, Path, S>;
type OperationWithoutBodyMethod = 'get' | 'delete' | 'options' | 'head' | 'trace';
type OperationWithoutBodyProps<DefaultParameterName extends string, SectionName extends string, Path extends string = string, S extends SchemaType = 'zod-schema'> = {
    method: OperationWithoutBodyMethod;
} & BaseOperationProps<DefaultParameterName, SectionName, Path, S>;
type Operation<DefaultParameterName extends string, SectionName extends string, Path extends string = string, S extends SchemaType = 'zod-schema'> = OperationWithBodyProps<DefaultParameterName, SectionName, Path, S> | OperationWithoutBodyProps<DefaultParameterName, SectionName, Path, S>;
declare function isOperationWithBodyProps<DefaultParameterName extends string, SectionName extends string, Path extends string, TypeOfSchema extends SchemaType = 'json-schema'>(operation: Operation<DefaultParameterName, SectionName, Path, TypeOfSchema>): operation is OperationWithBodyProps<DefaultParameterName, SectionName, Path, TypeOfSchema>;
declare enum ComponentType {
    SCHEMAS = "schemas",
    RESPONSES = "responses",
    REQUESTS = "requestBodies",
    PARAMETERS = "parameters"
}
type ParametersMap<Path extends string = string, S extends SchemaType = 'zod-schema'> = Record<PathParams<Path>, PathParameter> & Record<string, Parameter<S>>;
type BaseOperationProps<DefaultParameterName extends string, SectionName extends string, Path extends string = string, S extends SchemaType = 'zod-schema'> = {
    name: string;
    path: Path;
    description: string;
    parameters?: ParametersMap<Path, S>;
    disableDefaultParameters?: {
        [name in DefaultParameterName]?: boolean;
    };
    section?: SectionName;
    response: {
        status?: 200 | 201 | 418;
        description: string;
        schema: SchemaOfType<S>;
    };
};
type CreateStateProps<SchemaName extends string, DefaultParameterName extends string, SectionName extends string> = {
    metadata: Metadata;
    defaultParameters?: Record<DefaultParameterName, Parameter<'zod-schema'>>;
    schemas?: Record<SchemaName, {
        schema: OpenApiZodAny;
        section: SectionName;
    }>;
    sections?: Record<SectionName, {
        title: string;
        description: string;
    }>;
    errors?: readonly ApiError[];
};
declare function createState<SchemaName extends string, DefaultParameterName extends string, SectionName extends string>(props: CreateStateProps<SchemaName, DefaultParameterName, SectionName>): State<SchemaName, DefaultParameterName, SectionName>;
declare function getRef(state: State<string, string, string>, type: ComponentType, name: string): OpenApiZodAny;
declare const mapParameter: (param: Parameter<'zod-schema'>) => Parameter<'json-schema'>;

declare const schema: typeof extendApi;
type OpenApiProps<SchemaName extends string, DefaultParameterName extends string, SectionName extends string> = {
    metadata: Metadata;
    defaultParameters?: Record<DefaultParameterName, Parameter<'zod-schema'>>;
    schemas?: Record<SchemaName, {
        schema: OpenApiZodAny;
        section: SectionName;
    }>;
    sections?: Record<SectionName, {
        title: string;
        description: string;
    }>;
    errors?: readonly ApiError[];
};
type CodePostProcessor = (code: string) => Promise<string> | string;
type OpenApiPostProcessors = {
    apiCode: CodePostProcessor;
};
declare const createOpapiFromState: <SchemaName extends string, DefaultParameterName extends string, SectionName extends string>(state: State<SchemaName, DefaultParameterName, SectionName>) => {
    getModelRef: (name: SchemaName) => OpenApiZodAny;
    addOperation: <Path extends string>(operationProps: Operation<DefaultParameterName, SectionName, Path, "zod-schema">) => void;
    exportClient: (dir: string | undefined, openapiGeneratorEndpoint: string, postProcessors?: OpenApiPostProcessors) => Promise<void>;
    exportTypesBySection: (dir?: string) => Promise<void>;
    exportServer: (dir: string | undefined, useExpressTypes: boolean) => Promise<void>;
    exportOpenapi: (dir?: string) => void;
    exportState: (dir?: string) => void;
};
type OpenApi<SchemaName extends string = string, DefaultParameterName extends string = string, SectionName extends string = string> = ReturnType<typeof createOpapiFromState<SchemaName, DefaultParameterName, SectionName>>;
declare function OpenApi<SchemaName extends string, DefaultParameterName extends string, SectionName extends string>(props: OpenApiProps<SchemaName, DefaultParameterName, SectionName>): {
    getModelRef: (name: SchemaName) => OpenApiZodAny;
    addOperation: <Path extends string>(operationProps: Operation<DefaultParameterName, SectionName, Path, "zod-schema">) => void;
    exportClient: (dir: string | undefined, openapiGeneratorEndpoint: string, postProcessors?: OpenApiPostProcessors | undefined) => Promise<void>;
    exportTypesBySection: (dir?: string) => Promise<void>;
    exportServer: (dir: string | undefined, useExpressTypes: boolean) => Promise<void>;
    exportOpenapi: (dir?: string) => void;
    exportState: (dir?: string) => void;
};
declare namespace OpenApi {
    const fromState: <SchemaName extends string, DefaultParameterName extends string, SectionName extends string>(state: State<SchemaName, DefaultParameterName, SectionName>) => {
        getModelRef: (name: SchemaName) => OpenApiZodAny;
        addOperation: <Path extends string>(operationProps: Operation<DefaultParameterName, SectionName, Path, "zod-schema">) => void;
        exportClient: (dir: string | undefined, openapiGeneratorEndpoint: string, postProcessors?: OpenApiPostProcessors | undefined) => Promise<void>;
        exportTypesBySection: (dir?: string) => Promise<void>;
        exportServer: (dir: string | undefined, useExpressTypes: boolean) => Promise<void>;
        exportOpenapi: (dir?: string) => void;
        exportState: (dir?: string) => void;
    };
}
type SchemaOf<O extends OpenApi<any, any, any>> = O extends OpenApi<infer Skema, infer _Param, infer _Sexion> ? Skema : never;
type ParameterOf<O extends OpenApi<any, any, any>> = O extends OpenApi<infer _Skema, infer Param, infer _Sexion> ? Param : never;
type SectionOf<O extends OpenApi<any, any, any>> = O extends OpenApi<infer _Skema, infer _Param, infer Sexion> ? Sexion : never;

export { ApiError, CodePostProcessor, ComponentType, Metadata, OpenApi, OpenApiPostProcessors, OpenApiProps, Operation, OperationWithBodyProps, OperationWithoutBodyMethod, OperationWithoutBodyProps, Parameter, ParameterOf, ParametersMap, PathParameter, QueryParameterObject, QueryParameterStringArray, SchemaOf, SectionOf, StandardParameter, State, createState, getRef, isOperationWithBodyProps, mapParameter, schema };
