"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeployedStateSchema = exports.TargetDeployedStateSchema = exports.DeployedResourceStateSchema = exports.RuntimeEndpointDeployedStateSchema = exports.HttpGatewayDeployedStateSchema = exports.ABTestDeployedStateSchema = exports.ConfigBundleDeployedStateSchema = exports.DatasetDeployedStateSchema = exports.OnlineEvalDeployedStateSchema = exports.EvaluatorDeployedStateSchema = exports.CredentialDeployedStateSchema = exports.PolicyDeployedStateSchema = exports.PolicyEngineDeployedStateSchema = exports.ExternallyManagedStateSchema = exports.VpcConfigSchema = exports.CustomJwtAuthorizerSchema = exports.ExternallyManagedResourceSchema = exports.McpDeployedStateSchema = exports.McpLambdaDeployedStateSchema = exports.McpRuntimeDeployedStateSchema = exports.GatewayDeployedStateSchema = exports.MemoryDeployedStateSchema = exports.AgentCoreDeployedStateSchema = void 0;
exports.createValidatedDeployedStateSchema = createValidatedDeployedStateSchema;
const auth_1 = require("./auth");
const aws_targets_1 = require("./aws-targets");
const zod_1 = require("zod");
// ============================================================================
// Agent Deployed State
// ============================================================================
exports.AgentCoreDeployedStateSchema = zod_1.z.object({
    runtimeId: zod_1.z.string().min(1),
    runtimeArn: zod_1.z.string().min(1),
    roleArn: zod_1.z.string().min(1),
    sessionId: zod_1.z.string().optional(),
    memoryIds: zod_1.z.array(zod_1.z.string()).optional(),
    browserId: zod_1.z.string().optional(),
    codeInterpreterId: zod_1.z.string().optional(),
    /** The latest deployed version number of this runtime. */
    runtimeVersion: zod_1.z.number().int().min(1).optional(),
});
// ============================================================================
// Memory Deployed State
// ============================================================================
exports.MemoryDeployedStateSchema = zod_1.z.object({
    memoryId: zod_1.z.string().min(1),
    memoryArn: zod_1.z.string().min(1),
});
// ============================================================================
// MCP Gateway Deployed State
// ============================================================================
exports.GatewayDeployedStateSchema = zod_1.z.object({
    gatewayId: zod_1.z.string().min(1),
    gatewayArn: zod_1.z.string().min(1),
    gatewayUrl: zod_1.z.string().optional(),
});
// ============================================================================
// MCP Runtime Deployed State
// ============================================================================
exports.McpRuntimeDeployedStateSchema = zod_1.z.object({
    runtimeId: zod_1.z.string().min(1),
    runtimeArn: zod_1.z.string().min(1),
    runtimeEndpoint: zod_1.z.string().min(1),
});
// ============================================================================
// MCP Lambda Deployed State
// ============================================================================
exports.McpLambdaDeployedStateSchema = zod_1.z.object({
    functionArn: zod_1.z.string().min(1),
    functionName: zod_1.z.string().min(1),
});
// ============================================================================
// MCP Deployed State Container
// ============================================================================
exports.McpDeployedStateSchema = zod_1.z.object({
    gateways: zod_1.z.record(zod_1.z.string(), exports.GatewayDeployedStateSchema).optional(),
    runtimes: zod_1.z.record(zod_1.z.string(), exports.McpRuntimeDeployedStateSchema).optional(),
    lambdas: zod_1.z.record(zod_1.z.string(), exports.McpLambdaDeployedStateSchema).optional(),
});
// ============================================================================
// Externally Managed Resources
// ============================================================================
exports.ExternallyManagedResourceSchema = zod_1.z.object({
    name: zod_1.z.string().min(1),
});
exports.CustomJwtAuthorizerSchema = exports.ExternallyManagedResourceSchema.extend({
    allowedAudience: zod_1.z.array(zod_1.z.string()).optional(),
    allowedClients: zod_1.z.array(zod_1.z.string()).optional(),
    allowedScopes: zod_1.z.array(zod_1.z.string()).optional(),
    customClaims: zod_1.z.array(auth_1.CustomClaimValidationSchema).optional(),
    discoveryUrl: zod_1.z.string(),
});
exports.VpcConfigSchema = exports.ExternallyManagedResourceSchema.extend({
    securityGroups: zod_1.z.array(zod_1.z.string()),
    subnets: zod_1.z.array(zod_1.z.string()),
});
exports.ExternallyManagedStateSchema = zod_1.z.object({
    customJwtAuthorizer: exports.CustomJwtAuthorizerSchema.optional(),
    vpcConfig: exports.VpcConfigSchema.optional(),
});
// ============================================================================
// Policy Engine Deployed State
// ============================================================================
exports.PolicyEngineDeployedStateSchema = zod_1.z.object({
    policyEngineId: zod_1.z.string().min(1),
    policyEngineArn: zod_1.z.string().min(1),
});
// ============================================================================
// Policy Deployed State
// ============================================================================
exports.PolicyDeployedStateSchema = zod_1.z.object({
    policyId: zod_1.z.string().min(1),
    policyArn: zod_1.z.string().min(1),
    engineName: zod_1.z.string().min(1),
});
// ============================================================================
// Credential Deployed State
// ============================================================================
exports.CredentialDeployedStateSchema = zod_1.z.object({
    credentialProviderArn: zod_1.z.string().min(1),
    clientSecretArn: zod_1.z.string().optional(),
    callbackUrl: zod_1.z.string().optional(),
});
// ============================================================================
// Evaluator Deployed State
// ============================================================================
exports.EvaluatorDeployedStateSchema = zod_1.z.object({
    evaluatorId: zod_1.z.string().min(1),
    evaluatorArn: zod_1.z.string().min(1),
});
// ============================================================================
// Online Eval Config Deployed State
// ============================================================================
exports.OnlineEvalDeployedStateSchema = zod_1.z.object({
    onlineEvaluationConfigId: zod_1.z.string().min(1),
    onlineEvaluationConfigArn: zod_1.z.string().min(1),
    executionStatus: zod_1.z.enum(['ENABLED', 'DISABLED']).optional(),
    /** Agent name this online eval config monitors. */
    agent: zod_1.z.string().min(1).optional(),
    /** Runtime endpoint name scoped to this online eval config. */
    endpoint: zod_1.z.string().min(1).optional(),
});
// ============================================================================
// Dataset Deployed State
// ============================================================================
exports.DatasetDeployedStateSchema = zod_1.z.object({
    datasetId: zod_1.z.string().min(1),
    datasetArn: zod_1.z.string().min(1),
    contentHash: zod_1.z.string().optional(),
});
// ============================================================================
// Configuration Bundle Deployed State
// ============================================================================
exports.ConfigBundleDeployedStateSchema = zod_1.z.object({
    bundleId: zod_1.z.string().min(1),
    bundleArn: zod_1.z.string().min(1),
    versionId: zod_1.z.string().min(1),
});
// ============================================================================
// AB Test Deployed State
// ============================================================================
exports.ABTestDeployedStateSchema = zod_1.z.object({
    abTestId: zod_1.z.string().min(1),
    abTestArn: zod_1.z.string().min(1),
    /** IAM role ARN used by this AB test. */
    roleArn: zod_1.z.string().min(1).optional(),
    /** Whether the CLI auto-created this role (true = CLI should delete on cleanup). */
    roleCreatedByCli: zod_1.z.boolean().optional(),
    /** SHA-256 hash of the AB test configuration for change detection. */
    configHash: zod_1.z.string().optional(),
});
// ============================================================================
// HTTP Gateway Deployed State
// ============================================================================
exports.HttpGatewayDeployedStateSchema = zod_1.z.object({
    gatewayId: zod_1.z.string().min(1),
    gatewayArn: zod_1.z.string().min(1),
    gatewayUrl: zod_1.z.string().optional(),
    targetId: zod_1.z.string().min(1).optional(),
    roleArn: zod_1.z.string().min(1).optional(),
    roleCreatedByCli: zod_1.z.boolean().optional(),
});
// ============================================================================
// Runtime Endpoint Deployed State
// ============================================================================
exports.RuntimeEndpointDeployedStateSchema = zod_1.z.object({
    endpointId: zod_1.z.string().min(1),
    endpointArn: zod_1.z.string().min(1),
});
// ============================================================================
// Deployed Resource State
// ============================================================================
exports.DeployedResourceStateSchema = zod_1.z.object({
    runtimes: zod_1.z.record(zod_1.z.string(), exports.AgentCoreDeployedStateSchema).optional(),
    memories: zod_1.z.record(zod_1.z.string(), exports.MemoryDeployedStateSchema).optional(),
    mcp: exports.McpDeployedStateSchema.optional(),
    externallyManaged: exports.ExternallyManagedStateSchema.optional(),
    credentials: zod_1.z.record(zod_1.z.string(), exports.CredentialDeployedStateSchema).optional(),
    evaluators: zod_1.z.record(zod_1.z.string(), exports.EvaluatorDeployedStateSchema).optional(),
    onlineEvalConfigs: zod_1.z.record(zod_1.z.string(), exports.OnlineEvalDeployedStateSchema).optional(),
    datasets: zod_1.z.record(zod_1.z.string(), exports.DatasetDeployedStateSchema).optional(),
    configBundles: zod_1.z.record(zod_1.z.string(), exports.ConfigBundleDeployedStateSchema).optional(),
    abTests: zod_1.z.record(zod_1.z.string(), exports.ABTestDeployedStateSchema).optional(),
    httpGateways: zod_1.z.record(zod_1.z.string(), exports.HttpGatewayDeployedStateSchema).optional(),
    policyEngines: zod_1.z.record(zod_1.z.string(), exports.PolicyEngineDeployedStateSchema).optional(),
    policies: zod_1.z.record(zod_1.z.string(), exports.PolicyDeployedStateSchema).optional(),
    runtimeEndpoints: zod_1.z.record(zod_1.z.string(), exports.RuntimeEndpointDeployedStateSchema).optional(),
    stackName: zod_1.z.string().optional(),
    identityKmsKeyArn: zod_1.z.string().optional(),
});
// ============================================================================
// Target Deployed State
// ============================================================================
exports.TargetDeployedStateSchema = zod_1.z.object({
    resources: exports.DeployedResourceStateSchema.optional(),
});
exports.DeployedStateSchema = zod_1.z.object({
    targets: zod_1.z.record(aws_targets_1.DeploymentTargetNameSchema, exports.TargetDeployedStateSchema),
});
/**
 * Creates a DeployedState schema that validates target keys against aws-targets.
 * Ensures all keys in deployed-state exist as names in aws-targets.
 */
function createValidatedDeployedStateSchema(targetNames) {
    const targetNameSet = new Set(targetNames);
    return exports.DeployedStateSchema.refine(state => {
        const stateKeys = Object.keys(state.targets);
        return stateKeys.every(key => targetNameSet.has(key));
    }, {
        message: 'Deployed state contains target names not present in aws-targets',
    });
}
//# sourceMappingURL=deployed-state.js.map