import { z } from 'zod';

/**
 * Collection Bindings
 *
 * This module provides standardized tool bindings for Collections, representing
 * SQL table-like structures with CRUD + Search operations compatible with TanStack DB.
 *
 * Key Features:
 * - Generic collection bindings that work with any entity type
 * - Standardized tool naming: `COLLECTION_{COLLECTION}_*`
 * - Compatible with TanStack DB query-collection
 * - Full TypeScript support with proper type constraints
 * - Support for filtering, sorting, and pagination
 * - Simple id and title fields for human-readable identification
 */
/**
 * Base schema for collection entities
 * All collection entities must have an id, title, and audit trail fields
 */
declare const BaseCollectionEntitySchema: z.ZodObject<{
    id: z.ZodString;
    title: z.ZodString;
    created_at: z.ZodString;
    updated_at: z.ZodString;
    created_by: z.ZodOptional<z.ZodString>;
    updated_by: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
    id: string;
    title: string;
    created_at: string;
    updated_at: string;
    created_by?: string | undefined;
    updated_by?: string | undefined;
}, {
    id: string;
    title: string;
    created_at: string;
    updated_at: string;
    created_by?: string | undefined;
    updated_by?: string | undefined;
}>;
/**
 * Type helper for BaseCollectionEntitySchema
 */
type BaseCollectionEntitySchemaType = typeof BaseCollectionEntitySchema;
/**
 * Where expression schema for filtering
 * Supports TanStack DB predicate push-down patterns
 */
declare const WhereExpressionSchema: z.ZodUnion<[z.ZodObject<{
    field: z.ZodArray<z.ZodString, "many">;
    operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
    value: z.ZodUnknown;
}, "strip", z.ZodTypeAny, {
    field: string[];
    operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
    value?: unknown;
}, {
    field: string[];
    operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
    value?: unknown;
}>, z.ZodObject<{
    operator: z.ZodEnum<["and", "or", "not"]>;
    conditions: z.ZodArray<z.ZodObject<{
        field: z.ZodArray<z.ZodString, "many">;
        operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
        value: z.ZodUnknown;
    }, "strip", z.ZodTypeAny, {
        field: string[];
        operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
        value?: unknown;
    }, {
        field: string[];
        operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
        value?: unknown;
    }>, "many">;
}, "strip", z.ZodTypeAny, {
    operator: "and" | "or" | "not";
    conditions: {
        field: string[];
        operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
        value?: unknown;
    }[];
}, {
    operator: "and" | "or" | "not";
    conditions: {
        field: string[];
        operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
        value?: unknown;
    }[];
}>]>;
/**
 * Where expression type for filtering
 * Derived from WhereExpressionSchema
 */
type WhereExpression = z.infer<typeof WhereExpressionSchema>;
/**
 * Order by expression for sorting
 */
declare const OrderByExpressionSchema: z.ZodObject<{
    field: z.ZodArray<z.ZodString, "many">;
    direction: z.ZodEnum<["asc", "desc"]>;
    nulls: z.ZodOptional<z.ZodEnum<["first", "last"]>>;
}, "strip", z.ZodTypeAny, {
    field: string[];
    direction: "asc" | "desc";
    nulls?: "first" | "last" | undefined;
}, {
    field: string[];
    direction: "asc" | "desc";
    nulls?: "first" | "last" | undefined;
}>;
/**
 * List/Query input schema for collections
 * Compatible with TanStack DB LoadSubsetOptions
 */
declare const CollectionListInputSchema: z.ZodObject<{
    where: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
        field: z.ZodArray<z.ZodString, "many">;
        operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
        value: z.ZodUnknown;
    }, "strip", z.ZodTypeAny, {
        field: string[];
        operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
        value?: unknown;
    }, {
        field: string[];
        operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
        value?: unknown;
    }>, z.ZodObject<{
        operator: z.ZodEnum<["and", "or", "not"]>;
        conditions: z.ZodArray<z.ZodObject<{
            field: z.ZodArray<z.ZodString, "many">;
            operator: z.ZodEnum<["eq", "gt", "gte", "lt", "lte", "in", "like", "contains"]>;
            value: z.ZodUnknown;
        }, "strip", z.ZodTypeAny, {
            field: string[];
            operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
            value?: unknown;
        }, {
            field: string[];
            operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
            value?: unknown;
        }>, "many">;
    }, "strip", z.ZodTypeAny, {
        operator: "and" | "or" | "not";
        conditions: {
            field: string[];
            operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
            value?: unknown;
        }[];
    }, {
        operator: "and" | "or" | "not";
        conditions: {
            field: string[];
            operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
            value?: unknown;
        }[];
    }>]>>;
    orderBy: z.ZodOptional<z.ZodArray<z.ZodObject<{
        field: z.ZodArray<z.ZodString, "many">;
        direction: z.ZodEnum<["asc", "desc"]>;
        nulls: z.ZodOptional<z.ZodEnum<["first", "last"]>>;
    }, "strip", z.ZodTypeAny, {
        field: string[];
        direction: "asc" | "desc";
        nulls?: "first" | "last" | undefined;
    }, {
        field: string[];
        direction: "asc" | "desc";
        nulls?: "first" | "last" | undefined;
    }>, "many">>;
    limit: z.ZodOptional<z.ZodNumber>;
    offset: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
    where?: {
        field: string[];
        operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
        value?: unknown;
    } | {
        operator: "and" | "or" | "not";
        conditions: {
            field: string[];
            operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
            value?: unknown;
        }[];
    } | undefined;
    orderBy?: {
        field: string[];
        direction: "asc" | "desc";
        nulls?: "first" | "last" | undefined;
    }[] | undefined;
    limit?: number | undefined;
    offset?: number | undefined;
}, {
    where?: {
        field: string[];
        operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
        value?: unknown;
    } | {
        operator: "and" | "or" | "not";
        conditions: {
            field: string[];
            operator: "eq" | "gt" | "gte" | "lt" | "lte" | "in" | "like" | "contains";
            value?: unknown;
        }[];
    } | undefined;
    orderBy?: {
        field: string[];
        direction: "asc" | "desc";
        nulls?: "first" | "last" | undefined;
    }[] | undefined;
    limit?: number | undefined;
    offset?: number | undefined;
}>;
/**
 * Factory function to create list output schema for a specific collection type
 */
declare function createCollectionListOutputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
    items: z.ZodArray<T, "many">;
    totalCount: z.ZodOptional<z.ZodNumber>;
    hasMore: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
    items: T["_output"][];
    totalCount?: number | undefined;
    hasMore?: boolean | undefined;
}, {
    items: T["_input"][];
    totalCount?: number | undefined;
    hasMore?: boolean | undefined;
}>;
/**
 * Get by ID input schema
 */
declare const CollectionGetInputSchema: z.ZodObject<{
    id: z.ZodString;
}, "strip", z.ZodTypeAny, {
    id: string;
}, {
    id: string;
}>;
/**
 * Factory function to create get output schema
 */
declare function createCollectionGetOutputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
    item: z.ZodNullable<T>;
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
    item: z.ZodNullable<T>;
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
    item: z.ZodNullable<T>;
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
/**
 * Factory function to create insert input schema
 */
declare function createCollectionInsertInputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
    data: T;
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
    data: T;
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
    data: T;
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
/**
 * Factory function to create insert output schema
 */
declare function createCollectionInsertOutputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
    item: T;
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
    item: T;
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
    item: T;
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
/**
 * Factory function to create update input schema
 */
declare function createCollectionUpdateInputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
    id: z.ZodString;
    data: z.ZodObject<{
        [x: string]: z.ZodOptional<any>;
    }, any, any, {
        [x: string]: any;
    }, {
        [x: string]: any;
    }>;
}, "strip", z.ZodTypeAny, {
    id: string;
    data: {
        [x: string]: any;
    };
}, {
    id: string;
    data: {
        [x: string]: any;
    };
}>;
/**
 * Factory function to create update output schema
 */
declare function createCollectionUpdateOutputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
    item: T;
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
    item: T;
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
    item: T;
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
/**
 * Delete input schema
 */
declare const CollectionDeleteInputSchema: z.ZodObject<{
    id: z.ZodString;
}, "strip", z.ZodTypeAny, {
    id: string;
}, {
    id: string;
}>;
/**
 * Factory function to create delete output schema
 */
declare function createCollectionDeleteOutputSchema<T extends z.ZodTypeAny>(entitySchema: T): z.ZodObject<{
    item: T;
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
    item: T;
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
    item: T;
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
/**
 * Options for creating collection bindings
 */
interface CollectionBindingOptions {
    /**
     * If true, only LIST and GET operations will be included (read-only collection)
     * @default false
     */
    readOnly?: boolean;
}
/**
 * Creates generic collection bindings for a specific entity type
 *
 * This function generates standardized tool bindings that work with any collection/table
 * by accepting a custom entity schema and collection name. The bindings provide:
 * - COLLECTION_{NAME}_LIST - Query/search entities with filtering and sorting (required)
 * - COLLECTION_{NAME}_GET - Get a single entity by ID (required)
 * - COLLECTION_{NAME}_CREATE - Create a new entity (optional, excluded if readOnly=true)
 * - COLLECTION_{NAME}_UPDATE - Update an existing entity (optional, excluded if readOnly=true)
 * - COLLECTION_{NAME}_DELETE - Delete an entity (optional, excluded if readOnly=true)
 *
 * @param collectionName - The name of the collection/table (e.g., "users", "products", "orders")
 * @param entitySchema - The Zod schema for the entity type (must extend BaseCollectionEntitySchema)
 * @param options - Optional configuration for the collection bindings
 * @returns Array of tool bindings for Collection CRUD + Query operations
 *
 * @example
 * ```typescript
 * const UserSchema = z.object({
 *   id: z.string(),
 *   title: z.string(),
 *   created_at: z.string().datetime(),
 *   updated_at: z.string().datetime(),
 *   created_by: z.string().optional(),
 *   updated_by: z.string().optional(),
 *   email: z.string().email(),
 * });
 *
 * // Full CRUD collection
 * const USER_COLLECTION_BINDING = createCollectionBindings("users", UserSchema);
 *
 * // Read-only collection (only LIST and GET)
 * const READONLY_COLLECTION_BINDING = createCollectionBindings("products", ProductSchema, { readOnly: true });
 * ```
 */
declare function createCollectionBindings<TEntitySchema extends BaseCollectionEntitySchemaType, TName extends string>(collectionName: TName, entitySchema: TEntitySchema, options?: CollectionBindingOptions): ({
    name: `COLLECTION_${Uppercase<TName>}_LIST`;
    inputSchema: typeof CollectionListInputSchema;
    outputSchema: z.ZodObject<{
        items: z.ZodArray<TEntitySchema, "many">;
        totalCount: z.ZodOptional<z.ZodNumber>;
        hasMore: z.ZodOptional<z.ZodBoolean>;
    }, "strip", z.ZodTypeAny, {
        items: TEntitySchema["_output"][];
        totalCount?: number | undefined;
        hasMore?: boolean | undefined;
    }, {
        items: TEntitySchema["_input"][];
        totalCount?: number | undefined;
        hasMore?: boolean | undefined;
    }>;
} | {
    name: `COLLECTION_${Uppercase<TName>}_GET`;
    inputSchema: typeof CollectionGetInputSchema;
    outputSchema: z.ZodObject<{
        item: z.ZodNullable<TEntitySchema>;
    }, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
        item: z.ZodNullable<TEntitySchema>;
    }>, any> extends infer T ? { [k in keyof T]: T[k]; } : never, z.baseObjectInputType<{
        item: z.ZodNullable<TEntitySchema>;
    }> extends infer T_1 ? { [k_1 in keyof T_1]: T_1[k_1]; } : never>;
} | {
    name: `COLLECTION_${Uppercase<TName>}_CREATE`;
    inputSchema: z.ZodObject<{
        data: TEntitySchema;
    }, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
        data: TEntitySchema;
    }>, any> extends infer T_2 ? { [k_2 in keyof T_2]: T_2[k_2]; } : never, z.baseObjectInputType<{
        data: TEntitySchema;
    }> extends infer T_3 ? { [k_3 in keyof T_3]: T_3[k_3]; } : never>;
    outputSchema: z.ZodObject<{
        item: TEntitySchema;
    }, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
        item: TEntitySchema;
    }>, any> extends infer T_4 ? { [k_4 in keyof T_4]: T_4[k_4]; } : never, z.baseObjectInputType<{
        item: TEntitySchema;
    }> extends infer T_5 ? { [k_5 in keyof T_5]: T_5[k_5]; } : never>;
    opt: true;
} | {
    name: `COLLECTION_${Uppercase<TName>}_UPDATE`;
    inputSchema: z.ZodObject<{
        id: z.ZodString;
        data: z.ZodObject<{
            [x: string]: z.ZodOptional<any>;
        }, any, any, {
            [x: string]: any;
        }, {
            [x: string]: any;
        }>;
    }, "strip", z.ZodTypeAny, {
        id: string;
        data: {
            [x: string]: any;
        };
    }, {
        id: string;
        data: {
            [x: string]: any;
        };
    }>;
    outputSchema: z.ZodObject<{
        item: TEntitySchema;
    }, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
        item: TEntitySchema;
    }>, any> extends infer T_6 ? { [k_6 in keyof T_6]: T_6[k_6]; } : never, z.baseObjectInputType<{
        item: TEntitySchema;
    }> extends infer T_7 ? { [k_7 in keyof T_7]: T_7[k_7]; } : never>;
    opt: true;
} | {
    name: `COLLECTION_${Uppercase<TName>}_DELETE`;
    inputSchema: typeof CollectionDeleteInputSchema;
    outputSchema: z.ZodObject<{
        item: TEntitySchema;
    }, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
        item: TEntitySchema;
    }>, any> extends infer T_8 ? { [k_8 in keyof T_8]: T_8[k_8]; } : never, z.baseObjectInputType<{
        item: TEntitySchema;
    }> extends infer T_9 ? { [k_9 in keyof T_9]: T_9[k_9]; } : never>;
    opt: true;
})[];
type ReadOnlyCollectionBinding<TEntitySchema extends BaseCollectionEntitySchemaType, TUpperName extends Uppercase<string> = Uppercase<string>> = [
    {
        name: `COLLECTION_${TUpperName}_LIST`;
        inputSchema: typeof CollectionListInputSchema;
        outputSchema: ReturnType<typeof createCollectionListOutputSchema<TEntitySchema>>;
    },
    {
        name: `COLLECTION_${TUpperName}_GET`;
        inputSchema: typeof CollectionGetInputSchema;
        outputSchema: ReturnType<typeof createCollectionGetOutputSchema<TEntitySchema>>;
    }
];
/**
 * Type helper to extract the collection binding type
 */
type CollectionBinding<TEntitySchema extends BaseCollectionEntitySchemaType, TUpperName extends Uppercase<string> = Uppercase<string>> = [
    ...ReadOnlyCollectionBinding<TEntitySchema, TUpperName>,
    {
        name: `COLLECTION_${TUpperName}_CREATE`;
        inputSchema: ReturnType<typeof createCollectionInsertInputSchema<TEntitySchema>>;
        outputSchema: ReturnType<typeof createCollectionInsertOutputSchema<TEntitySchema>>;
        opt: true;
    },
    {
        name: `COLLECTION_${TUpperName}_UPDATE`;
        inputSchema: ReturnType<typeof createCollectionUpdateInputSchema<TEntitySchema>>;
        outputSchema: ReturnType<typeof createCollectionUpdateOutputSchema<TEntitySchema>>;
        opt: true;
    },
    {
        name: `COLLECTION_${TUpperName}_DELETE`;
        inputSchema: typeof CollectionDeleteInputSchema;
        outputSchema: ReturnType<typeof createCollectionDeleteOutputSchema<TEntitySchema>>;
        opt: true;
    }
];
/**
 * Type helper to extract tool names from a collection binding
 */
type CollectionTools<TEntitySchema extends BaseCollectionEntitySchemaType, TUpperName extends Uppercase<string> = Uppercase<string>> = CollectionBinding<TEntitySchema, TUpperName>[number]["name"];
type CollectionListInput = z.infer<typeof CollectionListInputSchema>;
type CollectionGetInput = z.infer<typeof CollectionGetInputSchema>;
type CollectionDeleteInput = z.infer<typeof CollectionDeleteInputSchema>;
type OrderByExpression = z.infer<typeof OrderByExpressionSchema>;
/**
 * Type helper for list output with generic item type
 */
type CollectionListOutput<T> = {
    items: T[];
    totalCount?: number;
    hasMore?: boolean;
};
/**
 * Type helper for get output with generic item type
 */
type CollectionGetOutput<T> = {
    item: T | null;
};
/**
 * Type helper for insert output with generic item type
 */
type CollectionInsertOutput<T> = {
    item: T;
};
/**
 * Type helper for update output with generic item type
 */
type CollectionUpdateOutput<T> = {
    item: T;
};
/**
 * Type helper for delete output with generic item type
 */
type CollectionDeleteOutput<T> = {
    item: T;
};
/**
 * Base collection entity type - inferred from BaseCollectionEntitySchema
 */
type BaseCollectionEntity = z.infer<typeof BaseCollectionEntitySchema>;

export { type BaseCollectionEntity, BaseCollectionEntitySchema, type BaseCollectionEntitySchemaType, type CollectionBinding, type CollectionBindingOptions, type CollectionDeleteInput, CollectionDeleteInputSchema, type CollectionDeleteOutput, type CollectionGetInput, CollectionGetInputSchema, type CollectionGetOutput, type CollectionInsertOutput, type CollectionListInput, CollectionListInputSchema, type CollectionListOutput, type CollectionTools, type CollectionUpdateOutput, type OrderByExpression, OrderByExpressionSchema, type ReadOnlyCollectionBinding, type WhereExpression, WhereExpressionSchema, createCollectionBindings, createCollectionDeleteOutputSchema, createCollectionGetOutputSchema, createCollectionInsertInputSchema, createCollectionInsertOutputSchema, createCollectionListOutputSchema, createCollectionUpdateInputSchema, createCollectionUpdateOutputSchema };
