"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetDeploymentEventInfoToolDefinition = exports.getDeploymentEventInfoResponseSchema = exports.deploymentEventSummarySchema = exports.runResultSummarySchema = exports.triggeredPlanSummarySchema = exports.deploymentEventContextSchema = exports.getDeploymentEventInfoParamsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var agentToolNames_js_1 = require("../shared/agentToolNames.js");
var schemas_js_1 = require("../shared/schemas.js");
/**
 * GetDeploymentEventInfoDefinition - Tool definition for fetching comprehensive deployment event information.
 */
exports.getDeploymentEventInfoParamsSchema = zod_1.z.object({
    deployment_event_id: zod_1.z.string().meta({
        description: 'Required. Deployment event ID.',
    }),
    include_plan_summaries: zod_1.z.boolean().optional().meta({
        description: 'Whether to include triggered plan run summaries. Default: true',
    }),
    include_run_result: zod_1.z.boolean().optional().meta({
        description: 'Whether to include the overall run result summary. Default: true',
    }),
});
// Schema for application context
var applicationContextSchema = zod_1.z.object({
    id: zod_1.z.string().meta({ description: 'Application ID' }),
    name: zod_1.z.string().optional().meta({ description: 'Application name' }),
});
// Schema for environment context
var environmentContextSchema = zod_1.z.object({
    id: zod_1.z.string().meta({ description: 'Environment ID' }),
    name: zod_1.z.string().optional().meta({ description: 'Environment name' }),
});
// Schema for plan overrides (configuration overrides applied to triggered plan runs)
var planOverridesSchema = zod_1.z.object({
    webUrl: zod_1.z.string().optional().meta({ description: 'Web URL override for the deployment' }),
    apiUrl: zod_1.z.string().optional().meta({ description: 'API URL override for the deployment' }),
    browserTypes: zod_1.z.array(zod_1.z.string()).optional().meta({ description: 'Browser types override' }),
    credentialsId: zod_1.z.string().optional().meta({ description: 'Credentials ID override' }),
    httpAuthCredentialsId: zod_1.z.string().optional().meta({ description: 'HTTP Auth credentials ID override' }),
    linkAgentLabels: zod_1.z.array(zod_1.z.string()).optional().meta({ description: 'Link Agent labels override' }),
    mobileDeviceIds: zod_1.z.array(zod_1.z.string()).optional().meta({ description: 'Mobile device IDs override' }),
    runMultiplier: zod_1.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.
exports.deploymentEventContextSchema = zod_1.z.object({
    application: applicationContextSchema.optional().meta({ description: 'Application this deployment is for' }),
    environment: environmentContextSchema.optional().meta({ description: 'Environment this deployment targets' }),
    revision: zod_1.z.string().optional().meta({ description: 'Source code revision (commit SHA)' }),
    planLabels: zod_1.z.array(zod_1.z.string()).optional().meta({ description: 'Plan labels used to filter which plans ran' }),
    branch: zod_1.z.string().optional().meta({ description: 'mabl branch to run tests from' }),
    sourceControl: schemas_js_1.sourceControlContextSchema.optional().meta({ description: 'Detailed source control context' }),
    planOverrides: planOverridesSchema.optional().meta({ description: 'Plan configuration overrides applied' }),
    properties: zod_1.z
        .record(zod_1.z.string(), zod_1.z.string())
        .optional()
        .meta({ description: 'Custom key-value properties passed with deployment' }),
});
// Schema for triggered plan summary
exports.triggeredPlanSummarySchema = zod_1.z.object({
    planId: zod_1.z.string().meta({ description: 'Plan ID' }),
    planRunId: zod_1.z.string().meta({ description: 'Plan run ID' }),
    planName: zod_1.z.string().optional().meta({ description: 'Plan name' }),
    status: zod_1.z.string().optional().meta({ description: 'Plan run status' }),
});
// Schema for run result summary
exports.runResultSummarySchema = zod_1.z.object({
    status: zod_1.z.string().optional().meta({ description: 'Overall status (passed, failed, running)' }),
    passRate: zod_1.z.number().optional().meta({ description: 'Pass rate as a percentage (0-100)' }),
    totalPlanRuns: zod_1.z.number().optional().meta({ description: 'Total number of plan runs' }),
    passedPlanRuns: zod_1.z.number().optional().meta({ description: 'Number of passed plan runs' }),
    failedPlanRuns: zod_1.z.number().optional().meta({ description: 'Number of failed plan runs' }),
    totalTestRuns: zod_1.z.number().optional().meta({ description: 'Total number of test runs across all plans' }),
    passedTestRuns: zod_1.z.number().optional().meta({ description: 'Number of passed test runs' }),
    failedTestRuns: zod_1.z.number().optional().meta({ description: 'Number of failed test runs' }),
});
exports.deploymentEventSummarySchema = zod_1.z.object({
    deploymentEventId: zod_1.z.string().meta({ description: 'Deployment event ID' }),
    eventTime: zod_1.z.string().optional().meta({ description: 'Event time as ISO string' }),
    receivedTime: zod_1.z.string().optional().meta({ description: 'Received time as ISO string' }),
});
exports.getDeploymentEventInfoResponseSchema = zod_1.z.object({
    summary: exports.deploymentEventSummarySchema.meta({ description: 'Summary information about the deployment event' }),
    context: exports.deploymentEventContextSchema.optional().meta({ description: 'Contextual information about the deployment' }),
    triggeredPlanSummaries: zod_1.z.array(exports.triggeredPlanSummarySchema).optional().meta({
        description: 'Summaries of plan runs triggered by this deployment',
    }),
    runResult: exports.runResultSummarySchema.optional().meta({ description: 'Overall run result summary' }),
});
exports.GetDeploymentEventInfoToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.GetDeploymentEventInfo,
    description: "Retrieves comprehensive information about a deployment event including status, timing, configuration, and triggered plan runs.\n\n**Do not call this tool without a real deployment_event_id.** Use the id from **deployment_run_context**, the user's message, **".concat(agentToolNames_js_1.AgentToolNames.QueryWorkspaceDeploymentEvents, "** (workspace scope), or another tool result. Never guess or pass an empty id.\n\nUse this tool to:\n- Understand the overall deployment event result and status\n- Get triggered plan run summaries and pass/fail counts\n- Learn about the deployment configuration (application, environment, revision, etc.)\n- Understand which plans were triggered by this deployment\n- Get timing information about the deployment event"),
    argumentsSchema: exports.getDeploymentEventInfoParamsSchema,
    responseSchema: exports.getDeploymentEventInfoResponseSchema,
});
//# sourceMappingURL=GetDeploymentEventInfoDefinition.js.map