import { z } from "zod";
import { ConnectionIdPropertySchema, ConnectionPropertySchema, AuthenticationIdPropertySchema, AppKeyPropertySchema, AppPropertySchema, ActionTypePropertySchema, ActionKeyPropertySchema, ActionPropertySchema, InputFieldPropertySchema, InputsPropertySchema, } from "../../types/properties";
import { withFormatter } from "../../utils/schema-utils";
import { NeedChoicesSchema } from "../../api/schemas";
// ============================================================================
// Input Field Choice Item Schema
// ============================================================================
export const InputFieldChoiceItemSchema = withFormatter(NeedChoicesSchema, {
    format: (item) => {
        const title = item.label || item.key || "Choice";
        const details = [];
        // Show key as detail if different from label
        if (item.label && item.key && item.label !== item.key) {
            details.push({ text: `Key: ${item.key}`, style: "dim" });
        }
        if (item.sample && item.sample !== item.key) {
            details.push({ text: `Sample: ${item.sample}`, style: "dim" });
        }
        if (item.value && item.value !== item.key) {
            details.push({ text: `Value: ${item.value}`, style: "normal" });
        }
        return {
            title,
            key: item.key,
            details,
        };
    },
});
// ============================================================================
// Plugin Schema Definition
// ============================================================================
const ListActionInputFieldChoicesDescription = "Get the available choices for a dynamic dropdown input field";
// Base schema for shared (optional) properties
const ListActionInputFieldChoicesBaseSchema = z.object({
    connection: ConnectionPropertySchema.optional().describe("Connection alias or connection ID (UUID or positive integer). Strings that match a key in the connections map are resolved against it; otherwise the value is used as a connection ID directly. Mutually exclusive with connectionId."),
    connectionId: ConnectionIdPropertySchema.nullable()
        .optional()
        .describe("Connection ID to use when listing available field choices. Required if the action needs a connection to populate dynamic dropdown options.")
        .meta({ deprecated: true }),
    /** @deprecated Use connection instead */
    authenticationId: AuthenticationIdPropertySchema.nullable()
        .optional()
        .meta({ deprecated: true }),
    inputs: InputsPropertySchema.optional().describe("Current input values that may affect available choices"),
    page: z
        .number()
        .int()
        .min(0)
        .optional()
        .describe("Page number for paginated results"),
    pageSize: z.number().min(1).optional().describe("Number of choices per page"),
    maxItems: z
        .number()
        .min(1)
        .optional()
        .describe("Maximum total items to return across all pages"),
    cursor: z.string().optional().describe("Cursor to start from"),
});
// Schema for docs/registry (new param names only)
export const ListActionInputFieldChoicesSchema = z
    .object({
    app: AppPropertySchema,
    actionType: ActionTypePropertySchema,
    action: ActionPropertySchema,
    inputField: InputFieldPropertySchema,
})
    .merge(ListActionInputFieldChoicesBaseSchema)
    .describe(ListActionInputFieldChoicesDescription)
    .meta({
    aliases: {
        appKey: "app",
        actionKey: "action",
        inputFieldKey: "inputField",
        connectionId: "connection",
        authenticationId: "connection",
    },
});
// Deprecated schema (backward compat)
const ListActionInputFieldChoicesSchemaDeprecated = z
    .object({
    appKey: AppKeyPropertySchema,
    actionType: ActionTypePropertySchema,
    actionKey: ActionKeyPropertySchema,
    inputFieldKey: z
        .string()
        .min(1)
        .describe("Input field key to get choices for."),
})
    .merge(ListActionInputFieldChoicesBaseSchema);
// Union for runtime validation (accepts either new or old names)
export const ListActionInputFieldChoicesInputSchema = z
    .union([
    ListActionInputFieldChoicesSchema,
    ListActionInputFieldChoicesSchemaDeprecated,
])
    .describe(ListActionInputFieldChoicesDescription);
