"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolFindFieldsOutputSchema = exports.findFieldsResultSchema = exports.findFieldsRankingMetadataSchema = exports.toolFindFieldsArgsSchemaTransformed = exports.toolFindFieldsArgsSchema = exports.TOOL_FIND_FIELDS_DESCRIPTION = void 0;
const zod_1 = require("zod");
const outputMetadata_1 = require("../outputMetadata");
const toolSchemaBuilder_1 = require("../toolSchemaBuilder");
exports.TOOL_FIND_FIELDS_DESCRIPTION = `Tool: "findFields"

Purpose:
Finds the most relevant Fields (Metrics & Dimensions) within Explores, returning detailed info about each.

Usage tips:
- Use "findExplores" first to discover available Explores and their field labels.
- Use full field labels in search terms (e.g. "Total Revenue", "Order Date").
- Pass all needed fields in one request.
- Fields are sorted by relevance, with a maximum score of 1 and a minimum of 0, so the top results are the most relevant.
- If results aren't relevant, retry with clearer or more specific terms.
- Results are paginated — use the next page token to get more results if needed.
`;
exports.toolFindFieldsArgsSchema = (0, toolSchemaBuilder_1.createToolSchema)()
    .extend({
    table: zod_1.z.string().describe('The table to search in.'),
    fieldSearchQueries: zod_1.z.array(zod_1.z.object({
        label: zod_1.z.string().describe('Full field label'),
    })),
})
    .withPagination()
    .build();
exports.toolFindFieldsArgsSchemaTransformed = exports.toolFindFieldsArgsSchema;
exports.findFieldsRankingMetadataSchema = zod_1.z.object({
    searchQueries: zod_1.z.array(zod_1.z.object({
        status: zod_1.z.enum(['success', 'error']).optional(),
        label: zod_1.z.string(),
        error: zod_1.z.string().optional(),
        results: zod_1.z.array(zod_1.z.object({
            name: zod_1.z.string(),
            label: zod_1.z.string(),
            tableName: zod_1.z.string(),
            fieldType: zod_1.z.string(),
            searchRank: zod_1.z.number().nullable().optional(),
            chartUsage: zod_1.z.number().nullable().optional(),
            verifiedChartUsage: zod_1.z.number().nullable().optional(),
        })),
        pagination: zod_1.z
            .object({
            page: zod_1.z.number(),
            pageSize: zod_1.z.number(),
            totalResults: zod_1.z.number(),
            totalPageCount: zod_1.z.number(),
        })
            .optional(),
    })),
});
const findFieldsSearchSuccessSchema = zod_1.z.object({
    status: zod_1.z.literal('success'),
    searchQuery: zod_1.z.string(),
    page: zod_1.z.number().nullable(),
    pageSize: zod_1.z.number().nullable(),
    totalPageCount: zod_1.z.number().nullable(),
    totalResults: zod_1.z.number().nullable(),
    fields: zod_1.z.array(zod_1.z.object({
        type: zod_1.z.string(),
        baseTable: zod_1.z.string(),
        name: zod_1.z.string(),
        fieldId: zod_1.z.string(),
        fieldType: zod_1.z.string(),
        fieldFilterType: zod_1.z.string(),
        searchRank: zod_1.z.number().nullable().optional(),
        chartUsage: zod_1.z.number().nullable().optional(),
        usageInVerifiedCharts: zod_1.z.number(),
        isFromJoinedTable: zod_1.z.boolean(),
        caseSensitiveFilters: zod_1.z.boolean().nullable(),
        note: zod_1.z.string().nullable(),
        label: zod_1.z.string(),
        aiHints: zod_1.z.array(zod_1.z.string()),
        description: zod_1.z.string().nullable(),
        categories: zod_1.z.array(zod_1.z.string()),
        emoji: zod_1.z.string().nullable(),
    })),
});
const findFieldsSearchErrorSchema = zod_1.z.object({
    status: zod_1.z.literal('error'),
    searchQuery: zod_1.z.string(),
    error: zod_1.z.string(),
});
exports.findFieldsResultSchema = zod_1.z.object({
    searchResults: zod_1.z.array(zod_1.z.discriminatedUnion('status', [
        findFieldsSearchSuccessSchema,
        findFieldsSearchErrorSchema,
    ])),
});
exports.toolFindFieldsOutputSchema = zod_1.z.object({
    result: zod_1.z.string(),
    metadata: outputMetadata_1.baseOutputMetadataSchema.extend({
        ranking: exports.findFieldsRankingMetadataSchema.optional(),
    }),
});
//# sourceMappingURL=toolFindFieldsArgs.js.map