import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { AgentToolNames } from '../shared/agentToolNames.js';
import { sourceControlContextSchema } from '../shared/schemas.js';
/**
 * GetDeploymentEventInfoDefinition - Tool definition for fetching comprehensive deployment event information.
 */
export const getDeploymentEventInfoParamsSchema = z.object({
    deployment_event_id: z.string().meta({
        description: 'Required. Deployment event ID.',
    }),
    include_plan_summaries: z.boolean().optional().meta({
        description: 'Whether to include triggered plan run summaries. Default: true',
    }),
    include_run_result: z.boolean().optional().meta({
        description: 'Whether to include the overall run result summary. Default: true',
    }),
});
// Schema for application context
const applicationContextSchema = z.object({
    id: z.string().meta({ description: 'Application ID' }),
    name: z.string().optional().meta({ description: 'Application name' }),
});
// Schema for environment context
const environmentContextSchema = z.object({
    id: z.string().meta({ description: 'Environment ID' }),
    name: z.string().optional().meta({ description: 'Environment name' }),
});
// Schema for plan overrides (configuration overrides applied to triggered plan runs)
const planOverridesSchema = z.object({
    webUrl: z.string().optional().meta({ description: 'Web URL override for the deployment' }),
    apiUrl: z.string().optional().meta({ description: 'API URL override for the deployment' }),
    browserTypes: z.array(z.string()).optional().meta({ description: 'Browser types override' }),
    credentialsId: z.string().optional().meta({ description: 'Credentials ID override' }),
    httpAuthCredentialsId: z.string().optional().meta({ description: 'HTTP Auth credentials ID override' }),
    linkAgentLabels: z.array(z.string()).optional().meta({ description: 'Link Agent labels override' }),
    mobileDeviceIds: z.array(z.string()).optional().meta({ description: 'Mobile device IDs override' }),
    runMultiplier: z.number().optional().meta({ description: 'Run multiplier for parallel test copies' }),
});
// Schema for deployment event context
// Note: The API's DeploymentEvent schema does not expose a direct 'branch' field.
// Branch information may be embedded in source_control or actions, but only 'revision'
// (commit SHA) is available as a top-level field on the deployment event.
export const deploymentEventContextSchema = z.object({
    application: applicationContextSchema.optional().meta({ description: 'Application this deployment is for' }),
    environment: environmentContextSchema.optional().meta({ description: 'Environment this deployment targets' }),
    revision: z.string().optional().meta({ description: 'Source code revision (commit SHA)' }),
    planLabels: z.array(z.string()).optional().meta({ description: 'Plan labels used to filter which plans ran' }),
    branch: z.string().optional().meta({ description: 'mabl branch to run tests from' }),
    sourceControl: sourceControlContextSchema.optional().meta({ description: 'Detailed source control context' }),
    planOverrides: planOverridesSchema.optional().meta({ description: 'Plan configuration overrides applied' }),
    properties: z
        .record(z.string(), z.string())
        .optional()
        .meta({ description: 'Custom key-value properties passed with deployment' }),
});
// Schema for triggered plan summary
export const triggeredPlanSummarySchema = z.object({
    planId: z.string().meta({ description: 'Plan ID' }),
    planRunId: z.string().meta({ description: 'Plan run ID' }),
    planName: z.string().optional().meta({ description: 'Plan name' }),
    status: z.string().optional().meta({ description: 'Plan run status' }),
});
// Schema for run result summary
export const runResultSummarySchema = z.object({
    status: z.string().optional().meta({ description: 'Overall status (passed, failed, running)' }),
    passRate: z.number().optional().meta({ description: 'Pass rate as a percentage (0-100)' }),
    totalPlanRuns: z.number().optional().meta({ description: 'Total number of plan runs' }),
    passedPlanRuns: z.number().optional().meta({ description: 'Number of passed plan runs' }),
    failedPlanRuns: z.number().optional().meta({ description: 'Number of failed plan runs' }),
    totalTestRuns: z.number().optional().meta({ description: 'Total number of test runs across all plans' }),
    passedTestRuns: z.number().optional().meta({ description: 'Number of passed test runs' }),
    failedTestRuns: z.number().optional().meta({ description: 'Number of failed test runs' }),
});
export const deploymentEventSummarySchema = z.object({
    deploymentEventId: z.string().meta({ description: 'Deployment event ID' }),
    eventTime: z.string().optional().meta({ description: 'Event time as ISO string' }),
    receivedTime: z.string().optional().meta({ description: 'Received time as ISO string' }),
});
export const getDeploymentEventInfoResponseSchema = z.object({
    summary: deploymentEventSummarySchema.meta({ description: 'Summary information about the deployment event' }),
    context: deploymentEventContextSchema.optional().meta({ description: 'Contextual information about the deployment' }),
    triggeredPlanSummaries: z.array(triggeredPlanSummarySchema).optional().meta({
        description: 'Summaries of plan runs triggered by this deployment',
    }),
    runResult: runResultSummarySchema.optional().meta({ description: 'Overall run result summary' }),
});
export const GetDeploymentEventInfoToolDefinition = defineTool({
    name: AgentToolNames.GetDeploymentEventInfo,
    description: `Retrieves comprehensive information about a deployment event including status, timing, configuration, and triggered plan runs.

**Do not call this tool without a real deployment_event_id.** Use the id from **deployment_run_context**, the user's message, **${AgentToolNames.QueryWorkspaceDeploymentEvents}** (workspace scope), or another tool result. Never guess or pass an empty id.

Use this tool to:
- Understand the overall deployment event result and status
- Get triggered plan run summaries and pass/fail counts
- Learn about the deployment configuration (application, environment, revision, etc.)
- Understand which plans were triggered by this deployment
- Get timing information about the deployment event`,
    argumentsSchema: getDeploymentEventInfoParamsSchema,
    responseSchema: getDeploymentEventInfoResponseSchema,
});
//# sourceMappingURL=GetDeploymentEventInfoDefinition.js.map