import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { STEP_INDEX_DESCRIPTION } from './shared/stepIndexDescription.js';
import { refreshedStepsResponseFields } from './shared/refreshedStepsResponseFields.js';
export const executeMoveStepsArgumentsSchema = z
    .object({
    start_step_index: z
        .string()
        .optional()
        .meta({
        description: `${STEP_INDEX_DESCRIPTION} First step to move (inclusive). Either start_step_index or step_id must be provided; if both are provided, step_id takes precedence.`,
    }),
    end_step_index: z
        .string()
        .optional()
        .meta({
        description: `${STEP_INDEX_DESCRIPTION} Last step to move (inclusive). Optional — when omitted, only the step identified by start_step_index / step_id is moved. When provided, must be at the same nesting level as the first step. If both end_step_index and end_step_id are provided, end_step_id takes precedence.`,
    }),
    step_id: z.string().optional().meta({
        description: 'Stable canonical step id of the first step to move (inclusive). Preferred over start_step_index when the test execution state exposes step ids — ids survive list mutations and avoid stale-index races. When both step_id and start_step_index are provided, step_id wins.',
    }),
    end_step_id: z.string().optional().meta({
        description: 'Stable canonical step id of the last step to move (inclusive). Optional — when omitted, only the step identified by step_id / start_step_index is moved. When provided, must be a sibling of step_id (same parent in the canonical step tree). Preferred over end_step_index. When both end_step_id and end_step_index are provided, end_step_id wins.',
    }),
    destination: z.enum(['new_group', 'existing_group', 'parent_level']).meta({
        description: '"new_group": wraps selected steps in a new step group. ' +
            '"existing_group": moves selected steps into an existing step group (specify target_group_position). ' +
            '"parent_level": extracts steps from their current group to the parent level.',
    }),
    group_name: z.string().optional().meta({
        description: 'Name for the new step group (only for destination "new_group"). This becomes the group\'s display label in the test (e.g. "Log in with test credentials", "Add item to cart"). Give it a clear, task-like name describing what the grouped steps accomplish.',
    }),
    target_group_position: z.string().optional().meta({
        description: 'Dot-notation position of the existing step group to move steps into (only for destination "existing_group"). Steps are appended to the end of the target group.',
    }),
})
    .superRefine((value, ctx) => {
    if (value.start_step_index === undefined && value.step_id === undefined) {
        ctx.addIssue({
            code: 'custom',
            path: ['start_step_index'],
            message: 'Provide either start_step_index or step_id to identify the first step to move.',
        });
    }
});
export const executeMoveStepsResponseSchema = z.object({
    success: z.boolean(),
    message: z.string().optional(),
    ...refreshedStepsResponseFields,
});
export const ExecuteMoveStepsToolDefinition = defineTool({
    name: 'execute_move_steps',
    description: 'Moves a range of steps between nesting levels. Three modes:\n' +
        '- "new_group": wraps steps in a new named step group (provide group_name to label it).\n' +
        '- "existing_group": moves steps into an existing step group at target_group_position (appended to end).\n' +
        '- "parent_level": extracts steps from their current group to the parent level.\n\n' +
        'Identify the first step with either a dot-notation index (start_step_index) or a stable step id (step_id). End fields (end_step_index / end_step_id) are optional — when omitted, only the first step is moved (e.g. wrapping a single step in a new group). When provided, the range is inclusive and must be at the same nesting level. The id-based form wins when both forms are provided. This tool cannot move steps into or out of flows.\n\n' +
        "WARNING: Moving steps changes all subsequent step indices. The refreshed step list is returned in this tool's output (updated_test_steps) — re-anchor on it before using other index-based tools (if absent on an older client, call get_test_context). Step ids, when available, remain stable across moves.",
    argumentsSchema: executeMoveStepsArgumentsSchema,
    responseSchema: executeMoveStepsResponseSchema,
});
//# sourceMappingURL=ExecuteMoveStepsDefinition.js.map