"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolGetMetadataOutputSchema = exports.getMetadataResultSchema = exports.getMetadataInputSchema = exports.GET_METADATA_DESCRIPTION = void 0;
const zod_1 = require("zod");
const outputMetadata_1 = require("../outputMetadata");
const discoveryToolNames_1 = require("./discoveryToolNames");
const toolFindExploresArgs_1 = require("./toolFindExploresArgs");
const GET_METADATA_DESCRIPTION = ({ runtime, }) => {
    const getMetadata = (0, discoveryToolNames_1.toolNameFor)('getMetadata', runtime);
    const grepFields = (0, discoveryToolNames_1.toolNameFor)('grepFields', runtime);
    const visualization = (0, discoveryToolNames_1.toolNameFor)('generateVisualization', runtime);
    return `Tool: ${getMetadata}

Purpose:
Get the full metadata for specific explores and/or fields that you already know the IDs of (typically from ${grepFields}). ${grepFields} is lean — it tells you WHICH fields exist; ${getMetadata} gives you the DETAIL you need to build a correct query: an explore's joined tables and table filters, and a field's filter type, case-sensitivity, hints, and whether it comes from a joined table.

Call this AFTER ${grepFields}, once you have narrowed down to the explore(s) and field(s) you intend to use, and BEFORE ${visualization}. You can ask for several explores and several fields across explores in a SINGLE call — batch everything you need at once instead of one request per item.

Each entry in \`requests\` is one of:
- \`{ "type": "explore", "exploreIds": ["orders", "customers"] }\` — full metadata for those explores (joined tables, table filters, field counts).
- \`{ "type": "field", "fields": [{ "exploreId": "orders", "fieldId": "orders_status" }] }\` — full metadata for those specific fields.
`;
};
exports.GET_METADATA_DESCRIPTION = GET_METADATA_DESCRIPTION;
const exploreMetadataRequestSchema = zod_1.z.object({
    type: zod_1.z.literal('explore'),
    exploreIds: zod_1.z
        .array(zod_1.z.string().min(1))
        .min(1)
        .describe('Explore IDs (names) to fetch full metadata for.'),
});
const fieldMetadataRequestSchema = zod_1.z.object({
    type: zod_1.z.literal('field'),
    fields: zod_1.z
        .array(zod_1.z.object({
        exploreId: zod_1.z
            .string()
            .min(1)
            .describe('The explore the field belongs to.'),
        fieldId: zod_1.z
            .string()
            .min(1)
            .describe('The fieldId, e.g. `orders_status`.'),
    }))
        .min(1)
        .describe('Specific fields to fetch full metadata for.'),
});
exports.getMetadataInputSchema = zod_1.z.object({
    requests: zod_1.z
        .array(zod_1.z.discriminatedUnion('type', [
        exploreMetadataRequestSchema,
        fieldMetadataRequestSchema,
    ]))
        .min(1)
        .max(20)
        .describe('A batch of explore and/or field metadata requests, resolved together in one call.'),
});
const getMetadataExploreFoundSchema = zod_1.z.object({
    exploreId: zod_1.z.string(),
    status: zod_1.z.literal('found'),
    label: zod_1.z.string(),
    description: zod_1.z.string().nullable(),
    hint: zod_1.z.string().nullable(),
    baseTable: zod_1.z.string(),
    joinedTables: zod_1.z.array(zod_1.z.string()),
    requiredFilters: zod_1.z.array(toolFindExploresArgs_1.findExploresRequiredFilterSchema),
    baseDimensions: zod_1.z.object({
        count: zod_1.z.number(),
        fieldIds: zod_1.z.array(zod_1.z.string()),
    }),
    baseMetrics: zod_1.z.object({
        count: zod_1.z.number(),
        fieldIds: zod_1.z.array(zod_1.z.string()),
    }),
});
const getMetadataExploreNotFoundSchema = zod_1.z.object({
    exploreId: zod_1.z.string(),
    status: zod_1.z.literal('not_found'),
    error: zod_1.z.string(),
});
const getMetadataFieldFoundSchema = zod_1.z.object({
    exploreId: zod_1.z.string(),
    fieldId: zod_1.z.string(),
    status: zod_1.z.literal('found'),
    kind: zod_1.z.enum(['dimension', 'metric']),
    fieldType: zod_1.z.string(),
    label: zod_1.z.string(),
    filterType: zod_1.z.string(),
    isFromJoinedTable: zod_1.z.boolean(),
    joinedTableName: zod_1.z.string().nullable(),
    caseSensitiveFilters: zod_1.z.boolean().nullable(),
    description: zod_1.z.string().nullable(),
    hint: zod_1.z.string().nullable(),
});
const getMetadataFieldNotFoundSchema = zod_1.z.object({
    exploreId: zod_1.z.string(),
    fieldId: zod_1.z.string(),
    status: zod_1.z.literal('not_found'),
    error: zod_1.z.string(),
});
exports.getMetadataResultSchema = zod_1.z.object({
    explores: zod_1.z.array(zod_1.z.union([
        getMetadataExploreFoundSchema,
        getMetadataExploreNotFoundSchema,
    ])),
    fields: zod_1.z.array(zod_1.z.union([getMetadataFieldFoundSchema, getMetadataFieldNotFoundSchema])),
});
exports.toolGetMetadataOutputSchema = zod_1.z.object({
    result: zod_1.z.string(),
    metadata: outputMetadata_1.baseOutputMetadataSchema,
});
//# sourceMappingURL=toolGetMetadataArgs.js.map