// This file is auto-generated by @hey-api/openapi-ts

import * as z from 'zod'

export const zAccessMode = z.enum([
  'ACCESS_MODE_UNSPECIFIED',
  'ACCESS_MODE_PUBLIC',
  'ACCESS_MODE_PRIVATE',
  'ACCESS_MODE_PRIVATE_ALL',
])

export const zAccessSubjectType = z.enum([
  'ACCESS_SUBJECT_TYPE_UNSPECIFIED',
  'ACCESS_SUBJECT_TYPE_ACCOUNT',
  'ACCESS_SUBJECT_TYPE_GROUP',
])

export const zAppRunnerLogStatus = z.enum([
  'APP_RUNNER_LOG_STATUS_UNSPECIFIED',
  'APP_RUNNER_LOG_STATUS_RUNNING',
  'APP_RUNNER_LOG_STATUS_SUCCEEDED',
  'APP_RUNNER_LOG_STATUS_FAILED',
  'APP_RUNNER_LOG_STATUS_PARTIAL_SUCCEEDED',
])

export const zAssignmentOperation = z.enum([
  'ASSIGNMENT_OPERATION_UNSPECIFIED',
  'ASSIGNMENT_OPERATION_LOAD',
  'ASSIGNMENT_OPERATION_UNLOAD',
])

export const zEnvironmentMode = z.enum([
  'ENVIRONMENT_MODE_UNSPECIFIED',
  'ENVIRONMENT_MODE_SHARED',
  'ENVIRONMENT_MODE_ISOLATED',
])

export const zRuntimeBackend = z.enum([
  'RUNTIME_BACKEND_UNSPECIFIED',
  'RUNTIME_BACKEND_K8S',
  'RUNTIME_BACKEND_EXTERNAL',
])

export const zPluginCategory = z.enum([
  'PLUGIN_CATEGORY_UNSPECIFIED',
  'PLUGIN_CATEGORY_MODEL',
  'PLUGIN_CATEGORY_TOOL',
])

export const zDeploymentStatus = z.enum([
  'DEPLOYMENT_STATUS_UNSPECIFIED',
  'DEPLOYMENT_STATUS_DEPLOYING',
  'DEPLOYMENT_STATUS_READY',
  'DEPLOYMENT_STATUS_FAILED',
  'DEPLOYMENT_STATUS_CANCELLED',
])

export const zDeploymentAction = z.enum([
  'DEPLOYMENT_ACTION_UNSPECIFIED',
  'DEPLOYMENT_ACTION_DEPLOY',
  'DEPLOYMENT_ACTION_PROMOTE',
  'DEPLOYMENT_ACTION_ROLLBACK',
  'DEPLOYMENT_ACTION_UNDEPLOY',
])

export const zDeveloperApiUrlStatus = z.enum([
  'DEVELOPER_API_URL_STATUS_UNSPECIFIED',
  'DEVELOPER_API_URL_STATUS_CONFIGURED',
  'DEVELOPER_API_URL_STATUS_NOT_CONFIGURED',
])

export const zEnvVarValueSource = z.enum([
  'ENV_VAR_VALUE_SOURCE_UNSPECIFIED',
  'ENV_VAR_VALUE_SOURCE_LITERAL',
  'ENV_VAR_VALUE_SOURCE_DSL_DEFAULT',
  'ENV_VAR_VALUE_SOURCE_LAST_DEPLOYMENT',
])

export const zEnvVarValueType = z.enum([
  'ENV_VAR_VALUE_TYPE_UNSPECIFIED',
  'ENV_VAR_VALUE_TYPE_STRING',
  'ENV_VAR_VALUE_TYPE_NUMBER',
  'ENV_VAR_VALUE_TYPE_SECRET',
])

export const zEnvironmentStatus = z.enum([
  'ENVIRONMENT_STATUS_UNSPECIFIED',
  'ENVIRONMENT_STATUS_ADMISSION',
  'ENVIRONMENT_STATUS_BOOTSTRAPPING',
  'ENVIRONMENT_STATUS_READY',
  'ENVIRONMENT_STATUS_FAILED',
  'ENVIRONMENT_STATUS_DELETING',
])

export const zRuntimeInstanceStatus = z.enum([
  'RUNTIME_INSTANCE_STATUS_UNSPECIFIED',
  'RUNTIME_INSTANCE_STATUS_UNDEPLOYED',
  'RUNTIME_INSTANCE_STATUS_DEPLOYING',
  'RUNTIME_INSTANCE_STATUS_READY',
  'RUNTIME_INSTANCE_STATUS_FAILED',
  'RUNTIME_INSTANCE_STATUS_DRIFTED',
  'RUNTIME_INSTANCE_STATUS_INVALID',
  'RUNTIME_INSTANCE_STATUS_UNDEPLOYING',
])

export const zAppRunnerLaunchProfileMode = z.enum([
  'APP_RUNNER_LAUNCH_PROFILE_MODE_UNSPECIFIED',
  'APP_RUNNER_LAUNCH_PROFILE_MODE_DEBUG',
])

export const zOperatorType = z.enum([
  'OPERATOR_TYPE_UNSPECIFIED',
  'OPERATOR_TYPE_END_USER',
  'OPERATOR_TYPE_ACCOUNT',
  'OPERATOR_TYPE_SERVICE_ACCOUNT',
  'OPERATOR_TYPE_SYSTEM',
])

export const zReleaseSource = z.enum([
  'RELEASE_SOURCE_UNSPECIFIED',
  'RELEASE_SOURCE_SOURCE_APP',
  'RELEASE_SOURCE_UPLOAD',
])

export const zReleaseEnvironmentActionKind = z.enum([
  'RELEASE_ENVIRONMENT_ACTION_KIND_UNSPECIFIED',
  'RELEASE_ENVIRONMENT_ACTION_KIND_PROMOTE',
  'RELEASE_ENVIRONMENT_ACTION_KIND_ROLLBACK',
  'RELEASE_ENVIRONMENT_ACTION_KIND_CURRENT',
  'RELEASE_ENVIRONMENT_ACTION_KIND_DEPLOYING',
  'RELEASE_ENVIRONMENT_ACTION_KIND_BLOCKED',
])

export const zAckStatus = z.enum([
  'ACK_STATUS_UNSPECIFIED',
  'ACK_STATUS_READY',
  'ACK_STATUS_FAILED',
])

export const zSlotType = z.enum([
  'SLOT_TYPE_UNSPECIFIED',
  'SLOT_TYPE_PLUGIN_CREDENTIAL',
  'SLOT_TYPE_ENV_VAR',
])

export const zRouteTargetKind = z.enum([
  'ROUTE_TARGET_KIND_UNSPECIFIED',
  'ROUTE_TARGET_KIND_K8S_SERVICE',
  'ROUTE_TARGET_KIND_DIRECT_UPSTREAM',
])

export const zPasswordChangeReason = z.enum([
  'PASSWORD_CHANGE_REASON_UNSPECIFIED',
  'PASSWORD_CHANGE_REASON_TEMP',
  'PASSWORD_CHANGE_REASON_EXPIRED',
  'PASSWORD_CHANGE_REASON_POLICY',
])

export const zOtelEndpointMode = z.enum([
  'OTEL_ENDPOINT_MODE_UNIFIED',
  'OTEL_ENDPOINT_MODE_DEDICATED',
])

export const zAppStatus = z.enum([
  'APP_STATUS_UNSPECIFIED',
  'APP_STATUS_PUBLISHED',
  'APP_STATUS_UNPUBLISHED',
  'APP_STATUS_DELETED',
])

export const zLimitType = z.enum([
  'LIMIT_TYPE_UNSPECIFIED',
  'LIMIT_TYPE_RPM',
  'LIMIT_TYPE_CONCURRENCY',
  'LIMIT_TYPE_TOKEN',
])

export const zLimitAction = z.enum([
  'LIMIT_ACTION_UNSPECIFIED',
  'LIMIT_ACTION_BLOCK',
  'LIMIT_ACTION_TRACK',
])

export const zPasswordStrengthLevel = z.enum([
  'PASSWORD_STRENGTH_LEVEL_UNSPECIFIED',
  'PASSWORD_STRENGTH_LEVEL_WEAK',
  'PASSWORD_STRENGTH_LEVEL_MEDIUM',
  'PASSWORD_STRENGTH_LEVEL_STRONG',
])

export const zPluginInstallationScope = z.enum([
  'PLUGIN_INSTALLATION_SCOPE_ALL',
  'PLUGIN_INSTALLATION_SCOPE_OFFICIAL_ONLY',
  'PLUGIN_INSTALLATION_SCOPE_OFFICIAL_AND_SPECIFIC_PARTNERS',
  'PLUGIN_INSTALLATION_SCOPE_NONE',
])

export const zLimitStatus = z.enum([
  'LIMIT_STATUS_UNSPECIFIED',
  'LIMIT_STATUS_NA',
  'LIMIT_STATUS_NORMAL',
  'LIMIT_STATUS_THROTTLED',
])

export const zAccessSubject = z.object({
  subjectType: zAccessSubjectType,
  subjectId: z.string(),
})

export const zAccessPolicy = z.object({
  id: z.string(),
  appInstanceId: z.string(),
  environmentId: z.string(),
  mode: zAccessMode,
  subjects: z.array(zAccessSubject),
  createdAt: z.iso.datetime(),
  updatedAt: z.iso.datetime(),
})

export const zActor = z.object({
  id: z.string(),
  displayName: z.string(),
})

export const zAccessChannels = z.object({
  id: z.string(),
  appInstanceId: z.string(),
  webAppEnabled: z.boolean(),
  developerApiEnabled: z.boolean(),
  updatedBy: zActor,
  createdAt: z.iso.datetime(),
  updatedAt: z.iso.datetime(),
})

export const zApiKey = z.object({
  id: z.string(),
  appInstanceId: z.string(),
  environmentId: z.string(),
  displayName: z.string(),
  maskedToken: z.string(),
  createdBy: zActor,
  createdAt: z.iso.datetime(),
  lastUsedAt: z.iso.datetime().optional(),
})

export const zAppInstance = z.object({
  id: z.string(),
  tenantId: z.string(),
  displayName: z.string(),
  description: z.string(),
  createdBy: zActor,
  updatedBy: zActor,
  createdAt: z.iso.datetime(),
  updatedAt: z.iso.datetime(),
})

export const zBootstrapAssignment = z.object({
  appId: z.string().optional(),
  environmentId: z.string().optional(),
  workflowId: z.string().optional(),
  runtimeInstanceId: z.string().optional(),
  workspaceId: z.string().optional(),
  runtimeInstanceVersion: z.string().optional(),
  bindingSnapshotVersion: z.string().optional(),
  executionTokenVersion: z.string().optional(),
  executionToken: z.string().optional(),
  releaseId: z.string().optional(),
  operation: zAssignmentOperation.optional(),
  deploymentId: z.string().optional(),
  requiresStatusReport: z.boolean().optional(),
})

export const zBootstrapRunnerResponse = z.object({
  runnerId: z.string().optional(),
  assignmentRevision: z.string().optional(),
  assignments: z.array(zBootstrapAssignment).optional(),
})

export const zCancelDeploymentRequest = z.object({
  appInstanceId: z.string().optional(),
  environmentId: z.string().optional(),
})

export const zComputeDeploymentOptionsRequest = z.object({
  environmentId: z.string().optional(),
  appInstanceId: z.string().optional(),
  dsl: z.string().optional(),
  sourceAppId: z.string().optional(),
  releaseId: z.string().optional(),
})

export const zCreateApiKeyRequest = z.object({
  appInstanceId: z.string().optional(),
  environmentId: z.string().optional(),
  displayName: z.string(),
})

export const zCreateApiKeyResponse = z.object({
  apiKey: zApiKey,
  token: z.string(),
})

export const zCreateAppInstanceRequest = z.object({
  displayName: z.string(),
  description: z.string().optional(),
})

export const zCreateAppInstanceResponse = z.object({
  appInstance: zAppInstance,
})

export const zCreateReleaseRequest = z.object({
  createAppInstance: z.boolean().optional(),
  appInstanceId: z.string().optional(),
  displayName: z.string().optional(),
  description: z.string().optional(),
  dsl: z.string().optional(),
  sourceAppId: z.string().optional(),
})

export const zCredentialCandidate = z.object({
  credentialId: z.string(),
  providerId: z.string(),
  category: zPluginCategory,
  displayName: z.string(),
  fromEnterprise: z.boolean(),
})

export const zCredentialSelectionInput = z.object({
  providerId: z.string(),
  category: zPluginCategory.optional(),
  credentialId: z.string(),
})

export const zCredentialSlot = z.object({
  providerId: z.string(),
  category: zPluginCategory,
  candidates: z.array(zCredentialCandidate),
  lastCredentialId: z.string(),
})

export const zDeleteApiKeyResponse = z.record(z.string(), z.unknown())

export const zDeleteAppInstanceResponse = z.record(z.string(), z.unknown())

export const zDeleteEnvironmentResponse = z.record(z.string(), z.unknown())

export const zDeleteReleaseResponse = z.record(z.string(), z.unknown())

export const zDeploymentOptionsAppInstanceDefaults = z.object({
  displayName: z.string(),
  description: z.string(),
})

export const zDeploymentOptionsReleaseDefaults = z.object({
  displayName: z.string(),
  description: z.string(),
})

export const zEnvVarInput = z.object({
  key: z.string(),
  value: z.string().optional(),
  valueSource: zEnvVarValueSource.optional(),
})

export const zEnvVarSlot = z.object({
  key: z.string(),
  valueType: zEnvVarValueType,
  description: z.string(),
  defaultValue: z.string().optional(),
  lastValue: z.string().optional(),
})

export const zDeploymentOptions = z.object({
  dslDigest: z.string(),
  appInstanceDefaults: zDeploymentOptionsAppInstanceDefaults,
  releaseDefaults: zDeploymentOptionsReleaseDefaults,
  credentialSlots: z.array(zCredentialSlot),
  envVarSlots: z.array(zEnvVarSlot),
})

export const zComputeDeploymentOptionsResponse = z.object({
  options: zDeploymentOptions,
})

export const zEnvironmentDeploymentRecord = z.object({
  id: z.string(),
  status: zDeploymentStatus,
  createdAt: z.iso.datetime(),
  finalizedAt: z.iso.datetime().optional(),
})

export const zError = z.object({
  code: z.string().optional(),
  message: z.string().optional(),
  phase: z.string().optional(),
  occurredAt: z.iso.datetime().optional(),
})

export const zDeveloperApiUrl = z.object({
  apiUrl: z.string(),
  status: zDeveloperApiUrlStatus,
  error: zError.optional(),
})

export const zApiKeySummary = z.object({
  apiKeyCount: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }),
  environmentCount: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }),
  developerApiEnabled: z.boolean(),
  developerApiUrl: zDeveloperApiUrl,
})

export const zEnvironment = z.object({
  id: z.string(),
  displayName: z.string(),
  description: z.string(),
  mode: zEnvironmentMode,
  backend: zRuntimeBackend,
  status: zEnvironmentStatus,
  statusMessage: z.string(),
  lastError: zError.optional(),
  namespace: z.string().optional(),
  managedBy: z.string().optional(),
  runtimeEndpoint: z.string().optional(),
  cpuCount: z.number(),
  createdAt: z.iso.datetime(),
  updatedAt: z.iso.datetime(),
})

export const zAccessEndpoint = z.object({
  environment: zEnvironment.optional(),
  endpointUrl: z.string(),
})

export const zCreateEnvironmentResponse = z.object({
  environment: zEnvironment.optional(),
})

export const zExchangeControlTokenRequest = z.object({
  joinToken: z.string().optional(),
})

export const zExchangeControlTokenResponse = z.object({
  accessToken: z.string().optional(),
  expiresAt: z.iso.datetime().optional(),
})

export const zExportReleaseDslResponse = z.object({
  dsl: z.string(),
})

export const zExternalAppRunnerConfig = z.object({
  runtimeEndpoint: z.string().optional(),
})

export const zGenerateAppRunnerLaunchProfileRequest = z.object({
  environmentId: z.string().optional(),
  mode: zAppRunnerLaunchProfileMode.optional(),
  controlEndpoint: z.string(),
  pluginDaemonBaseUrl: z.string(),
  runtimeListenAddr: z.string(),
  debugListenAddr: z.string().optional(),
})

export const zGenerateAppRunnerLaunchProfileResponse = z.object({
  environmentId: z.string().optional(),
  joinToken: z.string().optional(),
  configYaml: z.string().optional(),
  runtimeEndpoint: z.string().optional(),
  sourceCommands: z.array(z.string()).optional(),
  dockerCommands: z.array(z.string()).optional(),
})

export const zGetAccessChannelsResponse = z.object({
  accessChannels: zAccessChannels,
})

export const zGetAccessPolicyResponse = z.object({
  policy: zAccessPolicy,
})

export const zGetAppInstanceResponse = z.object({
  appInstance: zAppInstance,
})

export const zGetDeveloperApiSettingsResponse = z.object({
  accessChannels: zAccessChannels,
  environments: z.array(zEnvironment),
  apiKeys: z.array(zApiKey),
  developerApiUrl: zDeveloperApiUrl,
})

export const zGetEnvironmentResponse = z.object({
  environment: zEnvironment.optional(),
})

export const zK8sEnvironmentConfig = z.object({
  namespace: z.string().optional(),
})

export const zCreateEnvironmentRequest = z.object({
  displayName: z.string(),
  description: z.string().optional(),
  mode: zEnvironmentMode.optional(),
  backend: zRuntimeBackend.optional(),
  k8s: zK8sEnvironmentConfig.optional(),
  external: zExternalAppRunnerConfig.optional(),
  cpuCount: z.number().optional(),
  idempotencyKey: z.string(),
})

export const zListApiKeysResponse = z.object({
  apiKeys: z.array(zApiKey),
  apiUrl: z.string(),
})

export const zListReleaseCredentialCandidatesResponse = z.object({
  slots: z.array(zCredentialSlot),
})

export const zNamedRef = z.object({
  id: z.string(),
  displayName: z.string(),
})

export const zNewAppInstance = z.object({
  displayName: z.string().optional(),
  description: z.string().optional(),
})

export const zDeployRequest = z.object({
  dsl: z.string().optional(),
  sourceAppId: z.string().optional(),
  newAppInstance: zNewAppInstance.optional(),
  environmentId: z.string(),
  releaseName: z.string().optional(),
  releaseDescription: z.string().optional(),
  credentials: z.array(zCredentialSelectionInput).optional(),
  envVars: z.array(zEnvVarInput).optional(),
  idempotencyKey: z.string(),
  expectedDslDigest: z.string().optional(),
})

export const zOperator = z.object({
  type: zOperatorType,
  id: z.string(),
  displayName: z.string(),
})

export const zAppRunnerLog = z.object({
  id: z.string(),
  timestamp: z.iso.datetime(),
  workflowRunId: z.string(),
  status: zAppRunnerLogStatus,
  durationSeconds: z.number(),
  totalTokens: z.string(),
  workspace: zNamedRef,
  environment: zNamedRef,
  appInstance: zNamedRef,
  operator: zOperator,
  invokeFrom: z.string(),
  traceId: z.string(),
  difyTraceId: z.string(),
  gateCommitId: z.string(),
  body: z.string().optional(),
  attributesJson: z.string().optional(),
  resourceAttributesJson: z.string().optional(),
})

export const zGetAppRunnerLogResponse = z.object({
  appRunnerLog: zAppRunnerLog,
  lastArchived: z.iso.datetime().optional(),
})

export const zPrecheckReleaseRequest = z.object({
  appInstanceId: z.string().optional(),
  dsl: z.string().optional(),
  sourceAppId: z.string().optional(),
})

export const zPromoteRequest = z.object({
  appInstanceId: z.string().optional(),
  releaseId: z.string(),
  environmentId: z.string().optional(),
  credentials: z.array(zCredentialSelectionInput).optional(),
  envVars: z.array(zEnvVarInput).optional(),
  idempotencyKey: z.string(),
})

export const zReleaseContentMatch = z.object({
  releaseId: z.string(),
  displayName: z.string(),
  createdAt: z.iso.datetime(),
})

export const zReleaseEnvironmentAction = z.object({
  environment: zEnvironment,
  kind: zReleaseEnvironmentActionKind,
  disabledReason: z.string().optional(),
  requiresRuntimeInputs: z.boolean(),
  currentReleaseId: z.string(),
})

export const zReleaseEnvironmentDeployment = z.object({
  environment: zEnvironment,
  status: zRuntimeInstanceStatus,
})

export const zReportRuntimeAssignmentStatusRequest = z.object({
  deploymentId: z.string().optional(),
  runtimeInstanceId: z.string().optional(),
  releaseId: z.string().optional(),
  status: zAckStatus.optional(),
  lastError: zError.optional(),
  runnerId: z.string().optional(),
  assignmentRevision: z.string().optional(),
})

export const zReportRuntimeAssignmentStatusResponse = z.object({
  accepted: z.boolean().optional(),
  stale: z.boolean().optional(),
})

export const zRequiredSlot = z.object({
  type: zSlotType,
  providerId: z.string(),
  category: zPluginCategory,
  key: z.string(),
})

export const zRelease = z.object({
  id: z.string(),
  appInstanceId: z.string(),
  displayName: z.string(),
  description: z.string(),
  source: zReleaseSource,
  sourceAppId: z.string().optional(),
  gateCommitId: z.string(),
  requiredSlots: z.array(zRequiredSlot),
  createdBy: zActor,
  createdAt: z.iso.datetime(),
})

export const zCreateReleaseResponse = z.object({
  release: zRelease,
  appInstance: zAppInstance,
})

export const zDeployment = z.object({
  id: z.string(),
  appInstanceId: z.string(),
  status: zDeploymentStatus,
  action: zDeploymentAction,
  environment: zEnvironment,
  release: zRelease,
  error: zError.optional(),
  createdBy: zActor,
  createdAt: z.iso.datetime(),
  finalizedAt: z.iso.datetime().optional(),
})

export const zCancelDeploymentResponse = z.object({
  deployment: zDeployment,
})

export const zDeployResponse = z.object({
  appInstance: zAppInstance,
  release: zRelease,
  deployment: zDeployment,
})

export const zEnvironmentAppInstance = z.object({
  appInstance: zAppInstance.optional(),
  currentRelease: zRelease.optional(),
  status: zRuntimeInstanceStatus.optional(),
  lastError: zError.optional(),
  workspaceId: z.string().optional(),
  workspaceName: z.string().optional(),
})

export const zEnvironmentDeployment = z.object({
  appInstanceId: z.string(),
  environment: zEnvironment,
  status: zRuntimeInstanceStatus,
  currentRelease: zRelease.optional(),
  desiredRelease: zRelease.optional(),
  currentDeployment: zEnvironmentDeploymentRecord.optional(),
  error: zError.optional(),
  updatedAt: z.iso.datetime(),
  releasesBehind: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
})

export const zAppInstanceSummary = z.object({
  appInstance: zAppInstance,
  environmentDeployments: z.array(zEnvironmentDeployment),
  latestRelease: zRelease.optional(),
  accessChannels: zAccessChannels,
  apiKeySummary: zApiKeySummary,
})

export const zComputeReleaseDeploymentViewResponse = z.object({
  releases: z.array(zRelease),
  environmentDeployments: z.array(zEnvironmentDeployment),
  environmentActions: z.array(zReleaseEnvironmentAction),
  options: zDeploymentOptions.optional(),
})

export const zEnvironmentDeploymentHistoryItem = z.object({
  deployment: zDeployment.optional(),
  appInstanceId: z.string().optional(),
  appInstanceName: z.string().optional(),
  workspaceId: z.string().optional(),
  workspaceName: z.string().optional(),
})

export const zGetAppInstanceOverviewResponse = z.object({
  appInstance: zAppInstance,
  environmentDeployments: z.array(zEnvironmentDeployment),
  recentReleases: z.array(zRelease),
  accessChannels: zAccessChannels,
  apiKeySummary: zApiKeySummary,
  totalReleaseCount: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }),
})

export const zGetReleaseResponse = z.object({
  release: zRelease,
})

export const zListEnvironmentDeploymentsResponse = z.object({
  environmentDeployments: z.array(zEnvironmentDeployment),
})

export const zPromoteResponse = z.object({
  deployment: zDeployment,
})

export const zReleaseSummary = z.object({
  release: zRelease,
  deployedEnvironments: z.array(zReleaseEnvironmentDeployment),
  environmentActions: z.array(zReleaseEnvironmentAction),
  activeEnvironmentCount: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }),
})

export const zResolveApiTokenRouteRequest = z.object({
  token: z.string().optional(),
})

export const zResolveApiTokenRouteResponse = z.object({
  environmentId: z.string().optional(),
  namespace: z.string().optional(),
  serviceName: z.string().optional(),
  servicePort: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  environmentStatus: zEnvironmentStatus.optional(),
  appId: z.string().optional(),
  tenantId: z.string().optional(),
  runtimeInstanceId: z.string().optional(),
  observedReleaseId: z.string().optional(),
  runtimeInstanceStatus: zRuntimeInstanceStatus.optional(),
  revoked: z.boolean().optional(),
  unavailableReason: z.string().optional(),
  targetKind: zRouteTargetKind.optional(),
  directUpstream: z.string().optional(),
})

export const zRollbackRequest = z.object({
  appInstanceId: z.string().optional(),
  environmentId: z.string().optional(),
  targetReleaseId: z.string(),
  idempotencyKey: z.string(),
})

export const zRollbackResponse = z.object({
  deployment: zDeployment,
})

export const zRollbackTarget = z.object({
  release: zRelease,
  resolvedDeploymentId: z.string(),
  deployedAt: z.iso.datetime(),
  isCurrent: z.boolean(),
})

export const zRunnerInfo = z.object({
  hostname: z.string().optional(),
})

export const zBootstrapRunnerRequest = z.object({
  runner: zRunnerInfo.optional(),
})

export const zRuntimeArtifact = z.object({
  dslYaml: z.string().optional(),
  bindingSnapshotVersion: z.string().optional(),
  bindingSnapshot: z.record(z.string(), z.unknown()).optional(),
})

export const zRuntimeArtifactRequest = z.object({
  runtimeInstanceId: z.string().optional(),
  releaseId: z.string().optional(),
  deploymentId: z.string().optional(),
  bindingSnapshotVersion: z.string().optional(),
})

export const zBatchResolveRuntimeArtifactsRequest = z.object({
  requests: z.array(zRuntimeArtifactRequest).optional(),
})

export const zRuntimeArtifactResult = z.object({
  runtimeInstanceId: z.string().optional(),
  releaseId: z.string().optional(),
  artifact: zRuntimeArtifact.optional(),
  error: zError.optional(),
  deploymentId: z.string().optional(),
})

export const zBatchResolveRuntimeArtifactsResponse = z.object({
  results: z.array(zRuntimeArtifactResult).optional(),
})

export const zTestConnectionRequest = z.object({
  environmentId: z.string().optional(),
})

export const zTestConnectionResponse = z.object({
  reachable: z.boolean().optional(),
  message: z.string().optional(),
})

export const zUndeployRequest = z.object({
  appInstanceId: z.string().optional(),
  environmentId: z.string().optional(),
  idempotencyKey: z.string(),
})

export const zUndeployResponse = z.object({
  deployment: zDeployment,
})

export const zUnsupportedDslNode = z.object({
  id: z.string(),
  type: z.string(),
})

export const zUnsupportedToolProvider = z.object({
  nodeId: z.string(),
  providerType: z.string(),
  providerId: z.string().optional(),
  providerName: z.string().optional(),
  toolName: z.string().optional(),
})

export const zPrecheckReleaseResponse = z.object({
  gateCommitId: z.string(),
  canCreate: z.boolean(),
  matchedRelease: zReleaseContentMatch.optional(),
  unsupportedNodes: z.array(zUnsupportedDslNode),
  unsupportedToolProviders: z.array(zUnsupportedToolProvider),
})

export const zUpdateAccessChannelsRequest = z.object({
  appInstanceId: z.string().optional(),
  webAppEnabled: z.boolean().optional(),
  developerApiEnabled: z.boolean().optional(),
})

export const zUpdateAccessChannelsResponse = z.object({
  accessChannels: zAccessChannels,
})

export const zUpdateAccessPolicyRequest = z.object({
  appInstanceId: z.string().optional(),
  environmentId: z.string().optional(),
  mode: zAccessMode,
  subjects: z.array(zAccessSubject).optional(),
})

export const zUpdateAccessPolicyResponse = z.object({
  policy: zAccessPolicy,
})

export const zUpdateAppInstanceRequest = z.object({
  appInstanceId: z.string().optional(),
  displayName: z.string(),
  description: z.string().optional(),
})

export const zUpdateAppInstanceResponse = z.object({
  appInstance: zAppInstance,
})

export const zUpdateEnvironmentRequest = z.object({
  environmentId: z.string().optional(),
  displayName: z.string(),
  description: z.string().optional(),
  cpuCount: z.number().optional(),
})

export const zUpdateEnvironmentResponse = z.object({
  environment: zEnvironment.optional(),
})

export const zUpdateReleaseRequest = z.object({
  releaseId: z.string().optional(),
  displayName: z.string(),
  description: z.string().optional(),
})

export const zUpdateReleaseResponse = z.object({
  release: zRelease,
})

/**
 * Account represents a basic user account
 */
export const zAccount = z.object({
  id: z.string().optional(),
  email: z.string().optional(),
  name: z.string().optional(),
})

export const zAccountDetailGroup = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
})

/**
 * AccountInWorkspace represents account's role in a workspace
 */
export const zAccountInWorkspace = z.object({
  workspaceId: z.string().optional(),
  workspaceName: z.string().optional(),
  role: z.string().optional(),
})

/**
 * AccountDetail contains detailed account information
 */
export const zAccountDetail = z.object({
  account: zAccount.optional(),
  status: z.string().optional(),
  createdAt: z.iso.datetime().optional(),
  lastActiveAt: z.iso.datetime().optional(),
  workspaces: z.array(zAccountInWorkspace).optional(),
  groups: z.array(zAccountDetailGroup).optional(),
})

export const zAddGroupAppsRequest = z.object({
  id: z.string().optional(),
  app_ids: z.array(z.string()).optional(),
})

export const zBrandingInfo = z.object({
  enabled: z.boolean().optional(),
  applicationTitle: z.string().optional(),
  loginPageLogo: z.string().optional(),
  workspaceLogo: z.string().optional(),
  favicon: z.string().optional(),
})

export const zCheckPasswordStatusReply = z.object({
  requirePasswordChange: z.boolean().optional(),
  changeReason: zPasswordChangeReason.optional(),
  daysToExpire: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  message: z.string().optional(),
})

export const zClearDefaultWorkspaceReply = z.record(z.string(), z.unknown())

export const zCreateBearerTokenResponse = z.object({
  token: z.string().optional(),
})

export const zCreateMemberReply = z.object({
  id: z.string().optional(),
  password: z.string().optional(),
})

/**
 * Create member messages
 */
export const zCreateMemberReq = z.object({
  name: z.string().optional(),
  email: z.string().optional(),
  status: z.string().optional(),
})

export const zCreateNewGroupsReqGroup = z.object({
  name: z.string().optional(),
})

export const zCreateNewGroupsReq = z.object({
  groups: z.array(zCreateNewGroupsReqGroup).optional(),
})

export const zCreateResourceGroupRequest = z.object({
  name: z.string().optional(),
  description: z.string().optional(),
})

export const zCreateSecretKeyReply = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  secretKey: z.string().optional(),
  createdAt: z.iso.datetime().optional(),
  lastActive: z.iso.datetime().optional(),
})

export const zCreateSecretKeyReq = z.object({
  name: z.string().optional(),
})

export const zCreateUserReply = z.object({
  id: z.string().optional(),
  password: z.string().optional(),
})

export const zCreateUserReq = z.object({
  name: z.string().optional(),
  email: z.string().optional(),
  status: z.string().optional(),
})

/**
 * Create workspace messages
 */
export const zCreateWorkspaceReq = z.object({
  name: z.string().optional(),
  email: z.string().optional(),
  status: z.string().optional(),
})

export const zCurrentUserReply = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  email: z.string().optional(),
  interfaceLanguage: z.string().optional(),
  timezone: z.string().optional(),
})

export const zDashboardSsooidcLoginReply = z.object({
  url: z.string().optional(),
  state: z.string().optional(),
})

export const zDashboardSsoOauth2LoginReply = z.object({
  url: z.string().optional(),
  state: z.string().optional(),
})

/**
 * Dashboard SSO Login messages
 */
export const zDashboardSsosamlLoginReply = z.object({
  url: z.string().optional(),
})

export const zDeleteGroupsRes = z.object({
  message: z.string().optional(),
})

export const zDeleteMemberReply = z.object({
  account: zAccount.optional(),
})

export const zDeleteSecretKeyReply = z.object({
  message: z.string().optional(),
})

export const zDeleteUserReply = z.object({
  account: zAccount.optional(),
})

export const zDeleteWorkspaceReply = z.record(z.string(), z.unknown())

/**
 * System user setting messages
 */
export const zEnterpriseSystemUserSettingReply = z.object({
  ssoEnforcedForSignin: z.boolean().optional(),
  ssoEnforcedForSigninProtocol: z.string().optional(),
  enableEmailPasswordLogin: z.boolean().optional(),
})

export const zExternallyAccessibleApp = z.object({
  appId: z.string().optional(),
  tenantId: z.string().optional(),
  mode: z.string().optional(),
  name: z.string().optional(),
  updatedAt: z.string().optional(),
})

export const zGetBearerTokenResponse = z.object({
  maskedToken: z.string().optional(),
})

export const zGetClusterInfoReply = z.object({
  mode: z.string().optional(),
  clusterId: z.string().optional(),
  verifyMode: z.string().optional(),
})

export const zGetLicenseStatusReply = z.object({
  status: z.string().optional(),
})

export const zGetMfaInfoReply = z.object({
  userEnabled: z.boolean().optional(),
  userSetup: z.boolean().optional(),
  globalEnabled: z.boolean().optional(),
})

export const zGetMemberReply = z.object({
  account: zAccountDetail.optional(),
})

export const zGetUserReply = z.object({
  account: zAccountDetail.optional(),
})

export const zGetWebAppAccessModeRes = z.object({
  accessMode: z.string().optional(),
})

export const zGetWebAppAuthInfoRes = z.object({
  allowSso: z.boolean().optional(),
  allowEmailCodeLogin: z.boolean().optional(),
  allowEmailPasswordLogin: z.boolean().optional(),
})

export const zGetWebAppWhitelistSubjectsResMember = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  email: z.string().optional(),
  avatar: z.string().optional(),
})

export const zGroupAppItem = z.object({
  app_id: z.string().optional(),
  app_name: z.string().optional(),
  workspace_id: z.string().optional(),
  workspace_name: z.string().optional(),
  app_status: zAppStatus.optional(),
  token_usage: z.string().optional(),
  rpm: z.string().optional(),
  concurrency: z.string().optional(),
})

export const zHealthzReply = z.object({
  message: z.string().optional(),
  status: z.string().optional(),
})

export const zInnerAdmission = z.object({
  marker: z.string().optional(),
  concurrencyGroupIds: z.array(z.string()).optional(),
})

export const zInnerBatchGetWebAppAccessModesByIdReq = z.object({
  appIds: z.array(z.string()).optional(),
})

export const zInnerBatchGetWebAppAccessModesByIdRes = z.object({
  accessModes: z.record(z.string(), z.string()).optional(),
})

export const zInnerBatchIsUserAllowedToAccessWebAppReq = z.object({
  userId: z.string().optional(),
  appIds: z.array(z.string()).optional(),
})

export const zInnerBatchIsUserAllowedToAccessWebAppRes = z.object({
  permissions: z.record(z.string(), z.boolean()).optional(),
})

export const zInnerCleanAppRes = z.object({
  message: z.string().optional(),
})

export const zInnerGetWebAppAccessModeByCodeRes = z.object({
  accessMode: z.string().optional(),
})

export const zInnerGetWebAppAccessModeByIdRes = z.object({
  accessMode: z.string().optional(),
})

export const zInnerIsUserAllowedToAccessWebAppRes = z.object({
  result: z.boolean().optional(),
})

export const zInnerListExternallyAccessibleAppsReq = z.object({
  page: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  limit: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  mode: z.string().optional(),
  name: z.string().optional(),
})

export const zInnerListExternallyAccessibleAppsRes = z.object({
  data: z.array(zExternallyAccessibleApp).optional(),
  total: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  hasMore: z.boolean().optional(),
})

export const zInnerReleaseAdmissionRequest = z.object({
  admission: zInnerAdmission.optional(),
})

export const zInnerReleaseAdmissionResponse = z.record(z.string(), z.unknown())

export const zInnerTryAddAccountToDefaultWorkspaceReply = z.object({
  workspaceId: z.string().optional(),
  joined: z.boolean().optional(),
  message: z.string().optional(),
})

/**
 * Inner API messages
 */
export const zInnerTryAddAccountToDefaultWorkspaceReq = z.object({
  accountId: z.string().optional(),
})

export const zIsUserAllowedToAccessWebAppRes = z.object({
  result: z.boolean().optional(),
})

export const zIssueMcpTokenReply = z.object({
  token: z.string().optional(),
  expiresAt: z.string().optional(),
  tokenType: z.string().optional(),
})

export const zIssueMcpTokenReq = z.object({
  userId: z.string().optional(),
  tenantId: z.string().optional(),
  appId: z.string().optional(),
  audience: z.string().optional(),
})

export const zJoinWorkspaceReply = z.object({
  message: z.string().optional(),
})

/**
 * Join workspace messages
 */
export const zJoinWorkspaceReq = z.object({
  id: z.string().optional(),
  email: z.string().optional(),
  role: z.string().optional(),
  rbacRole: z.string().optional(),
})

export const zLimitConfig = z.object({
  type: zLimitType.optional(),
  threshold: z.string().optional(),
  action: zLimitAction.optional(),
  reached: z.boolean().optional(),
})

export const zInnerGroupConfig = z.object({
  id: z.string().optional(),
  enabled: z.boolean().optional(),
  membershipId: z.string().optional(),
  limits: z.array(zLimitConfig).optional(),
})

export const zInnerResolveResponse = z.object({
  appId: z.string().optional(),
  groups: z.array(zInnerGroupConfig).optional(),
  blocked: z.boolean().optional(),
  blockGroupId: z.string().optional(),
  blockReason: z.string().optional(),
  admission: zInnerAdmission.optional(),
})

export const zListGroupAppsResponse = z.object({
  items: z.array(zGroupAppItem).optional(),
  total: z.string().optional(),
})

export const zLoginTypesReply = z.object({
  enabledEmailCodeLogin: z.boolean().optional(),
  enableEmailPasswordLogin: z.boolean().optional(),
  isAllowRegister: z.boolean().optional(),
  isAllowCreateWorkspace: z.boolean().optional(),
})

export const zLoginTypesReq = z.object({
  enabledEmailCodeLogin: z.boolean().optional(),
  enableEmailPasswordLogin: z.boolean().optional(),
  isAllowRegister: z.boolean().optional(),
  isAllowCreateWorkspace: z.boolean().optional(),
})

export const zMfaBackupCodesRes = z.object({
  codes: z.array(z.string()).optional(),
  validCounts: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  createdAt: z.iso.datetime().optional(),
})

export const zMfaDeleteBackupCodesRes = z.object({
  message: z.string().optional(),
})

export const zMfaDeleteRes = z.object({
  token: z.string().optional(),
})

export const zMfaDownloadBackupCodesSummaryRes = z.object({
  content: z.string().optional(),
})

export const zMfaEnrollReq = z.object({
  code: z.string().optional(),
})

export const zMfaEnrollRes = z.object({
  token: z.string().optional(),
})

export const zMfaGetEnrollInfoRes = z.object({
  qrCode: z.string().optional(),
  secret: z.string().optional(),
})

export const zMfaModifyRes = z.object({
  message: z.string().optional(),
})

export const zOAuth2Config = z.object({
  clientId: z.string().optional(),
  clientSecret: z.string().optional(),
  authUrl: z.string().optional(),
  tokenUrl: z.string().optional(),
  userinfoUrl: z.string().optional(),
  scopes: z.string().optional(),
  enablePkce: z.boolean().optional(),
})

export const zOAuth2LoginReply = z.object({
  url: z.string().optional(),
  state: z.string().optional(),
})

export const zOidcConfig = z.object({
  issuerUrl: z.string().optional(),
  clientId: z.string().optional(),
  clientSecret: z.string().optional(),
  enablePkce: z.boolean().optional(),
})

export const zOidcReply = z.object({
  url: z.string().optional(),
  state: z.string().optional(),
})

export const zOtelExporterEndpoint = z.object({
  endpoint: z.string().optional(),
  compression: z.string().optional(),
  protocol: z.enum(['HTTP_PROTOBUF', 'HTTP_JSON', 'GRPC']).optional(),
  timeout: z
    .string()
    .regex(/^-?(?:0|[1-9]\d{0,11})(?:\.\d{1,9})?s$/)
    .optional(),
  headers: z.record(z.string(), z.string()).optional(),
  tlsCaPem: z.string().optional(),
  tlsInsecure: z.boolean().optional(),
  tlsClientCertPem: z.string().optional(),
  tlsClientKeyPem: z.string().optional(),
  enabled: z.boolean().optional(),
  tlsInsecureSkipVerify: z.boolean().optional(),
})

export const zEndpointReply = z.object({
  mode: zOtelEndpointMode.optional(),
  metricsEndpoint: zOtelExporterEndpoint.optional(),
  tracesEndpoint: zOtelExporterEndpoint.optional(),
})

export const zOtelExporterStatusReply = z.object({
  connectedAt: z.iso.datetime().optional(),
  bytesPushed: z.string().optional(),
  itemsInQueue: z.string().optional(),
  logs: z.string().optional(),
  status: z.enum(['RUNNING', 'ERROR', 'STOPPED']).optional(),
})

export const zPasswordPolicyConfig = z.object({
  minLength: z
    .int()
    .min(0, { error: 'Invalid value: Expected uint32 to be >= 0' })
    .max(4294967295, { error: 'Invalid value: Expected uint32 to be <= 4294967295' })
    .optional(),
  requireDigit: z.boolean().optional(),
  requireLowercase: z.boolean().optional(),
  requireUppercase: z.boolean().optional(),
  requireSpecial: z.boolean().optional(),
  forbidRepeated: z.boolean().optional(),
  forbidSequential: z.boolean().optional(),
  expiryEnabled: z.boolean().optional(),
  expiryDays: z
    .int()
    .min(0, { error: 'Invalid value: Expected uint32 to be >= 0' })
    .max(4294967295, { error: 'Invalid value: Expected uint32 to be <= 4294967295' })
    .optional(),
})

export const zPasswordStrengthReply = z.object({
  level: zPasswordStrengthLevel.optional(),
})

export const zPasswordStrengthReq = z.object({
  password: z.string().optional(),
})

export const zPluginInstallationPermissionInfo = z.object({
  pluginInstallationScope: z.string().optional(),
  restrictToMarketplaceOnly: z.boolean().optional(),
})

export const zPluginInstallationSettingsReply = z.object({
  pluginInstallationScope: zPluginInstallationScope.optional(),
  restrictToMarketplaceOnly: z.boolean().optional(),
})

export const zRbacRole = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  description: z.string().optional(),
  permissions: z.array(z.string()).optional(),
})

export const zGetMemberRbacRolesReply = z.object({
  accountId: z.string().optional(),
  roles: z.array(zRbacRole).optional(),
})

export const zResetMemberPasswordReply = z.object({
  id: z.string().optional(),
  password: z.string().optional(),
})

/**
 * Reset member password messages
 */
export const zResetMemberPasswordReq = z.object({
  id: z.string().optional(),
})

export const zResetPasswordReply = z.object({
  message: z.string().optional(),
})

/**
 * Password reset messages
 */
export const zResetPasswordReq = z.object({
  currentPassword: z.string().optional(),
  newPassword: z.string().optional(),
  confirmPassword: z.string().optional(),
})

export const zResetUserPasswordReply = z.object({
  id: z.string().optional(),
  password: z.string().optional(),
})

export const zResetUserPasswordReq = z.object({
  id: z.string().optional(),
})

export const zResourceGroupDetail = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  description: z.string().optional(),
  enabled: z.boolean().optional(),
  rpm_limit: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  rpm_action: zLimitAction.optional(),
  concurrency_limit: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  concurrency_action: zLimitAction.optional(),
  token_quota: z.string().optional(),
  token_action: zLimitAction.optional(),
  created_at: z.string().optional(),
  updated_at: z.string().optional(),
})

export const zResourceGroupItem = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  description: z.string().optional(),
  enabled: z.boolean().optional(),
  rpm_limit: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  concurrency_limit: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  token_quota: z.string().optional(),
  token_usage: z.string().optional(),
  app_count: z.string().optional(),
  rpm_status: zLimitStatus.optional(),
  conc_status: zLimitStatus.optional(),
  created_at: z.string().optional(),
  updated_at: z.string().optional(),
})

export const zListResourceGroupsResponse = z.object({
  items: z.array(zResourceGroupItem).optional(),
  total: z.string().optional(),
})

/**
 * ResourceQuota represents usage quota for a resource
 */
export const zResourceQuota = z.object({
  used: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  limit: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  enabled: z.boolean().optional(),
})

export const zLicenseStatus = z.object({
  status: z.string().optional(),
  expiredAt: z.string().optional(),
  workspaces: zResourceQuota.optional(),
})

export const zLimitFields = z.object({
  workspaceMembers: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  workspaces: zResourceQuota.optional(),
  appRunnerEnvCpus: zResourceQuota.optional(),
})

/**
 * License information
 */
export const zLicenseInfo = z.object({
  uuid: z.string().optional(),
  expiredAt: z.iso.datetime().optional(),
  clusterId: z.string().optional(),
  product: z.string().optional(),
  limits: zLimitFields.optional(),
})

/**
 * License RPC messages
 */
export const zGetLicenseReply = z.object({
  license: zLicenseInfo.optional(),
})

/**
 * SSO Configuration messages
 */
export const zSamlConfig = z.object({
  idpSsoUrl: z.string().optional(),
  certificate: z.string().optional(),
})

export const zSamlLoginReply = z.object({
  url: z.string().optional(),
})

export const zSsoIdPProvider = z.object({
  protocol: z.string().optional(),
  provider: z.string().optional(),
  samlConfig: zSamlConfig.optional(),
  oidcConfig: zOidcConfig.optional(),
  oauth2Config: zOAuth2Config.optional(),
})

export const zSsoSettings = z.object({
  ssoEnforced: z.boolean().optional(),
  sessionTimeout: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  ssoIdpProvider: zSsoIdPProvider.optional(),
})

export const zAuthSettingsReply = z.object({
  userSsoSettings: zSsoSettings.optional(),
  webSsoSettings: zSsoSettings.optional(),
  dashboardSsoSettings: zSsoSettings.optional(),
  userSsoSamlAcsUrl: z.string().optional(),
  userSsoOidcCallbackUrl: z.string().optional(),
  userSsoOauth2CallbackUrl: z.string().optional(),
  webSsoSamlAcsUrl: z.string().optional(),
  webSsoOidcCallbackUrl: z.string().optional(),
  webSsoOauth2CallbackUrl: z.string().optional(),
  webSsoMembersSamlAcsUrl: z.string().optional(),
  webSsoMembersOidcCallbackUrl: z.string().optional(),
  webSsoMembersOauth2CallbackUrl: z.string().optional(),
  dashboardSsoSamlAcsUrl: z.string().optional(),
  dashboardSsoOidcCallbackUrl: z.string().optional(),
  dashboardSsoOauth2CallbackUrl: z.string().optional(),
})

export const zAuthSettingsReq = z.object({
  ssoType: z.string().optional(),
  ssoSettings: zSsoSettings.optional(),
})

export const zSsoSettingsReply = z.object({
  enabled: z.boolean().optional(),
})

export const zScimSettings = z.object({
  enabled: z.boolean().optional(),
  lastSyncTime: z.iso.datetime().optional(),
})

export const zSearchAppItem = z.object({
  app_id: z.string().optional(),
  app_name: z.string().optional(),
  workspace_id: z.string().optional(),
  workspace_name: z.string().optional(),
  app_status: zAppStatus.optional(),
  icon: z.string().optional(),
  icon_type: z.string().optional(),
  icon_background: z.string().optional(),
  created_by_name: z.string().optional(),
})

export const zSearchAppsResponse = z.object({
  items: z.array(zSearchAppItem).optional(),
  total: z.string().optional(),
})

export const zSecretKey = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  secretKeyMasked: z.string().optional(),
  createdAt: z.iso.datetime().optional(),
  lastActive: z.iso.datetime().optional(),
})

export const zSetDefaultWorkspaceReply = z.object({
  workspaceId: z.string().optional(),
})

export const zSetDefaultWorkspaceReq = z.object({
  id: z.string().optional(),
})

export const zSubjectAccountData = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  email: z.string().optional(),
  avatar: z.string().optional(),
})

export const zSubjectGroupData = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  groupSize: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
})

export const zCreateNewGroupsRes = z.object({
  groups: z.array(zSubjectGroupData).optional(),
})

export const zGetGroupsRes = z.object({
  groups: z.array(zSubjectGroupData).optional(),
})

export const zGetJoinedGroupsRes = z.object({
  groups: z.array(zSubjectGroupData).optional(),
})

export const zGetWebAppWhitelistSubjectsRes = z.object({
  groups: z.array(zSubjectGroupData).optional(),
  members: z.array(zGetWebAppWhitelistSubjectsResMember).optional(),
})

/**
 * Subject represents a subject (user or group) in access control
 */
export const zSubject = z.object({
  subjectId: z.string().optional(),
  subjectType: z.string().optional(),
  accountData: zSubjectAccountData.optional(),
  groupData: zSubjectGroupData.optional(),
})

export const zEnvironmentAccessPolicy = z.object({
  environment: zEnvironment,
  policy: zAccessPolicy.optional(),
  resolvedSubjects: z.array(zSubject),
})

export const zGetAccessSettingsResponse = z.object({
  accessChannels: zAccessChannels,
  environmentPolicies: z.array(zEnvironmentAccessPolicy),
  webAppEndpoints: z.array(zAccessEndpoint).optional(),
  cliEndpoint: zAccessEndpoint.optional(),
})

export const zGetGroupSubjectsRes = z.object({
  subjects: z.array(zSubject).optional(),
})

export const zSearchForWhilteListCandidatesRes = z.object({
  subjects: z.array(zSubject).optional(),
  currPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  hasMore: z.boolean().optional(),
})

export const zSystemUserSettingReply = z.object({
  isAllowRegister: z.boolean().optional(),
  enableEmailPasswordLogin: z.boolean().optional(),
})

export const zSystemUserSettingReq = z.object({
  isAllowRegister: z.boolean().optional(),
  enableEmailPasswordLogin: z.boolean().optional(),
})

export const zTestConnectionReply = z.object({
  success: z.boolean().optional(),
  error: z.string().optional(),
})

export const zToggleEndpointRequest = z.object({
  enabled: z.boolean().optional(),
})

export const zToggleTraceProviderRequest = z.object({
  id: z.string().optional(),
  enabled: z.boolean().optional(),
})

/**
 * TraceProvider is one configured trace-export destination. Trace data
 * collected by the enterprise collector is fanned out to every enabled
 * destination. Credentials carries per-provider secret values (e.g. Langfuse
 * public/secret keys); Settings carries non-secret options (e.g. host,
 * project). Secret credential values are redacted on read and preserved on
 * write when the client echoes the redaction sentinel back (same round-trip
 * contract as endpoint headers / TLS keys).
 */
export const zTraceProvider = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  provider: z.string().optional(),
  endpoint: z.string().optional(),
  protocol: z.string().optional(),
  credentials: z.record(z.string(), z.string()).optional(),
  settings: z.record(z.string(), z.string()).optional(),
  enabled: z.boolean().optional(),
})

/**
 * TestTraceProviderRequest tests connectivity/auth for a destination config
 * before (or without) persisting it. When credentials carry the redaction
 * sentinel, the stored secret for the destination with the same id is used.
 */
export const zTestTraceProviderRequest = z.object({
  provider: zTraceProvider.optional(),
})

/**
 * TraceProviderField describes one credential or setting field of a provider in
 * the static catalog: the key the dashboard sends back, its display label,
 * whether it is required, and (for credentials) whether it is a secret that
 * gets redacted.
 */
export const zTraceProviderField = z.object({
  key: z.string().optional(),
  displayName: z.string().optional(),
  required: z.boolean().optional(),
  secret: z.boolean().optional(),
})

/**
 * TraceProviderDescriptor is one entry in the static provider catalog: the
 * field definitions and transport defaults for a provider type. The dashboard
 * uses it to render the add/edit form and to know which fields are secret.
 */
export const zTraceProviderDescriptor = z.object({
  provider: z.string().optional(),
  displayName: z.string().optional(),
  credentialFields: z.array(zTraceProviderField).optional(),
  settingFields: z.array(zTraceProviderField).optional(),
  defaultProtocol: z.string().optional(),
  supportedProtocols: z.array(z.string()).optional(),
})

export const zListTraceProvidersReply = z.object({
  providers: z.array(zTraceProvider).optional(),
  catalog: z.array(zTraceProviderDescriptor).optional(),
})

export const zUpdateAccessModeReq = z.object({
  appId: z.string().optional(),
  accessMode: z.string().optional(),
})

export const zUpdateAccessModeRes = z.object({
  message: z.string().optional(),
})

export const zUpdateBrandingInfoReq = z.object({
  enabled: z.boolean().optional(),
  applicationTitle: z.string().optional(),
  loginPageLogo: z.string().optional(),
  workspaceLogo: z.string().optional(),
  favicon: z.string().optional(),
})

export const zUpdateGroupSubjectsReq = z.object({
  groupId: z.string().optional(),
  subjects: z.array(zSubject).optional(),
})

export const zUpdateGroupSubjectsRes = z.object({
  message: z.string().optional(),
})

export const zUpdateGroupsReqGroup = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
})

export const zUpdateGroupsReq = z.object({
  groups: z.array(zUpdateGroupsReqGroup).optional(),
})

export const zUpdateGroupsRes = z.object({
  groups: z.array(zSubjectGroupData).optional(),
})

export const zUpdateJoinedGroupsReq = z.object({
  accountId: z.string().optional(),
  groupIds: z.array(z.string()).optional(),
})

export const zUpdateJoinedGroupsRes = z.object({
  message: z.string().optional(),
})

export const zUpdateLicenseReply = z.object({
  message: z.string().optional(),
})

export const zUpdateLicenseReq = z.object({
  licenseId: z.string().optional(),
})

export const zUpdateMfaStatusReq = z.object({
  enabled: z.boolean().optional(),
})

export const zUpdateMfaStatusRes = z.object({
  message: z.string().optional(),
})

export const zUpdateMemberRbacRolesReply = z.object({
  accountId: z.string().optional(),
  roles: z.array(zRbacRole).optional(),
})

export const zUpdateMemberRbacRolesReq = z.object({
  id: z.string().optional(),
  roleIds: z.array(z.string()).optional(),
})

export const zUpdateMemberReply = z.object({
  account: zAccount.optional(),
})

/**
 * Update member messages
 */
export const zUpdateMemberReq = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  email: z.string().optional(),
  status: z.string().optional(),
})

export const zUpdateMembersInGroupsReq = z.object({
  groupId: z.string().optional(),
  accountIds: z.array(z.string()).optional(),
})

export const zUpdateMembersInGroupsRes = z.object({
  message: z.string().optional(),
})

export const zUpdateOfflineLicenseReply = z.object({
  message: z.string().optional(),
})

export const zUpdateOfflineLicenseReq = z.object({
  offlineCode: z.string().optional(),
})

export const zUpdatePluginInstallationSettingsRequest = z.object({
  pluginInstallationScope: zPluginInstallationScope.optional(),
  restrictToMarketplaceOnly: z.boolean().optional(),
})

export const zUpdateResourceGroupRequest = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  description: z.string().optional(),
  enabled: z.boolean().optional(),
  rpm_limit: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  rpm_action: zLimitAction.optional(),
  concurrency_limit: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  concurrency_action: zLimitAction.optional(),
  token_quota: z.string().optional(),
  token_action: zLimitAction.optional(),
})

export const zUpdateUserReply = z.object({
  account: zAccountDetail.optional(),
})

export const zUpdateUserReq = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  email: z.string().optional(),
  status: z.string().optional(),
})

/**
 * Web app auth info messages
 */
export const zUpdateWebAppAuthInfoReq = z.object({
  allowSso: z.boolean().optional(),
  allowEmailCodeLogin: z.boolean().optional(),
  allowEmailPasswordLogin: z.boolean().optional(),
})

export const zUpdateWebAppAuthInfoRes = z.object({
  message: z.string().optional(),
})

export const zUpdateWebAppWhitelistSubjectsReq = z.object({
  appId: z.string().optional(),
  subjects: z.array(zSubject).optional(),
  accessMode: z.string().optional(),
})

export const zUpdateWebAppWhitelistSubjectsRes = z.object({
  message: z.string().optional(),
})

/**
 * Update workspace messages
 */
export const zUpdateWorkspaceReq = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  email: z.string().optional(),
  status: z.string().optional(),
})

export const zUpsertTraceProviderReply = z.object({
  provider: zTraceProvider.optional(),
})

/**
 * UpsertTraceProviderRequest creates a destination when id is empty (a new id
 * is allocated) or updates the destination with the given id otherwise.
 */
export const zUpsertTraceProviderRequest = z.object({
  provider: zTraceProvider.optional(),
})

export const zWebAppAuthInfo = z.object({
  allowSso: z.boolean().optional(),
  allowEmailCodeLogin: z.boolean().optional(),
  allowEmailPasswordLogin: z.boolean().optional(),
})

/**
 * Info configuration messages
 */
export const zInfoConfigReply = z.object({
  SSOEnforcedForSignin: z.boolean().optional(),
  SSOEnforcedForSigninProtocol: z.string().optional(),
  SSOEnforcedForWeb: z.boolean().optional(),
  SSOEnforcedForWebProtocol: z.string().optional(),
  EnableEmailCodeLogin: z.boolean().optional(),
  EnableEmailPasswordLogin: z.boolean().optional(),
  IsAllowRegister: z.boolean().optional(),
  IsAllowCreateWorkspace: z.boolean().optional(),
  License: zLicenseStatus.optional(),
  Branding: zBrandingInfo.optional(),
  WebAppAuth: zWebAppAuthInfo.optional(),
  PluginInstallationPermission: zPluginInstallationPermissionInfo.optional(),
  EnableAppDeploy: z.boolean().optional(),
})

export const zWebOAuth2LoginReply = z.object({
  url: z.string().optional(),
  state: z.string().optional(),
})

export const zWebOidcLoginReply = z.object({
  url: z.string().optional(),
})

export const zWebSamlLoginReply = z.object({
  url: z.string().optional(),
})

/**
 * Workspace represents a workspace entity
 */
export const zWorkspace = z.object({
  id: z.string().optional(),
  name: z.string().optional(),
  status: z.string().optional(),
  createdAt: z.iso.datetime().optional(),
  owner: zAccount.optional(),
})

export const zCreateWorkspaceReply = z.object({
  workspace: zWorkspace.optional(),
})

export const zGetDefaultWorkspaceReply = z.object({
  workspaceId: z.string().optional(),
  workspace: zWorkspace.optional(),
})

export const zGetWorkspaceReply = z.object({
  workspace: zWorkspace.optional(),
})

export const zUpdateWorkspaceReply = z.object({
  workspace: zWorkspace.optional(),
})

export const zWorkspaceInfoReply = z.object({
  WorkspaceMembers: zResourceQuota.optional(),
})

/**
 * Workspace permission
 */
export const zWorkspacePermission = z.object({
  workspaceId: z.string().optional(),
  allowMemberInvite: z.boolean().optional(),
  allowOwnerTransfer: z.boolean().optional(),
})

export const zGetWorkspacePermissionReply = z.object({
  permission: zWorkspacePermission.optional(),
})

export const zUpdateWorkspacePermissionReply = z.object({
  message: z.string().optional(),
  permission: zWorkspacePermission.optional(),
})

/**
 * Update workspace permission messages
 */
export const zUpdateWorkspacePermissionReq = z.object({
  id: z.string().optional(),
  permission: zWorkspacePermission.optional(),
})

/**
 * CursorPagination: pagination by cursor token
 */
export const zCursorPagination = z.object({
  pageSize: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  nextCursor: z.string().optional(),
  prevCursor: z.string().optional(),
  hasNextPage: z.boolean().optional(),
  hasPrevPage: z.boolean().optional(),
  totalCount: z.string().optional(),
})

export const zListAppRunnerLogsResponse = z.object({
  appRunnerLogs: z.array(zAppRunnerLog),
  pagination: zCursorPagination,
  lastArchived: z.iso.datetime().optional(),
})

/**
 * Pagination ： Just for pagination by page
 */
export const zPagination = z.object({
  totalCount: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  perPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  currentPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  totalPages: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
})

export const zDashboardListAppInstancesResponse = z.object({
  appInstances: z.array(zAppInstance),
  pagination: zPagination,
})

export const zDashboardListEnvironmentDeploymentsResponse = z.object({
  deployments: z.array(zEnvironmentDeploymentHistoryItem).optional(),
  pagination: zPagination.optional(),
})

export const zListAppInstanceSummariesResponse = z.object({
  appInstanceSummaries: z.array(zAppInstanceSummary),
  pagination: zPagination,
})

export const zListAppInstancesResponse = z.object({
  appInstances: z.array(zAppInstance),
  pagination: zPagination,
})

export const zListDeploymentsResponse = z.object({
  deployments: z.array(zDeployment),
  pagination: zPagination,
})

export const zListEnvironmentAppInstancesResponse = z.object({
  appInstances: z.array(zEnvironmentAppInstance).optional(),
  pagination: zPagination.optional(),
})

export const zListEnvironmentsResponse = z.object({
  environments: z.array(zEnvironment),
  pagination: zPagination,
})

export const zListReleaseSummariesResponse = z.object({
  releaseSummaries: z.array(zReleaseSummary),
  pagination: zPagination,
})

export const zListReleasesResponse = z.object({
  releases: z.array(zRelease),
  pagination: zPagination,
})

export const zListRollbackTargetsResponse = z.object({
  rollbackTargets: z.array(zRollbackTarget),
  pagination: zPagination,
})

export const zListMembersReply = z.object({
  data: z.array(zAccountDetail).optional(),
  pagination: zPagination.optional(),
})

export const zListSecretKeysReply = z.object({
  data: z.array(zSecretKey).optional(),
  pagination: zPagination.optional(),
})

export const zListUsersReply = z.object({
  data: z.array(zAccountDetail).optional(),
  pagination: zPagination.optional(),
})

export const zListWorkspacesReply = z.object({
  data: z.array(zWorkspace).optional(),
  pagination: zPagination.optional(),
})

export const zAppInstanceServiceListAppInstanceSummariesQuery = z.object({
  pageNumber: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  resultsPerPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  displayName: z.string().optional(),
  environmentId: z.string().optional(),
})

/**
 * OK
 */
export const zAppInstanceServiceListAppInstanceSummariesResponse = zListAppInstanceSummariesResponse

export const zAppInstanceServiceListAppInstancesQuery = z.object({
  pageNumber: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  resultsPerPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  displayName: z.string().optional(),
  environmentId: z.string().optional(),
})

/**
 * OK
 */
export const zAppInstanceServiceListAppInstancesResponse = zListAppInstancesResponse

export const zAppInstanceServiceCreateAppInstanceBody = zCreateAppInstanceRequest

/**
 * OK
 */
export const zAppInstanceServiceCreateAppInstanceResponse = zCreateAppInstanceResponse

export const zAppInstanceServiceDeleteAppInstancePath = z.object({
  appInstanceId: z.string(),
})

/**
 * OK
 */
export const zAppInstanceServiceDeleteAppInstanceResponse = zDeleteAppInstanceResponse

export const zAppInstanceServiceGetAppInstancePath = z.object({
  appInstanceId: z.string(),
})

/**
 * OK
 */
export const zAppInstanceServiceGetAppInstanceResponse = zGetAppInstanceResponse

export const zAppInstanceServiceUpdateAppInstanceBody = zUpdateAppInstanceRequest

export const zAppInstanceServiceUpdateAppInstancePath = z.object({
  appInstanceId: z.string(),
})

/**
 * OK
 */
export const zAppInstanceServiceUpdateAppInstanceResponse = zUpdateAppInstanceResponse

export const zAccessServiceGetAccessChannelsPath = z.object({
  appInstanceId: z.string(),
})

/**
 * OK
 */
export const zAccessServiceGetAccessChannelsResponse = zGetAccessChannelsResponse

export const zAccessServiceUpdateAccessChannelsBody = zUpdateAccessChannelsRequest

export const zAccessServiceUpdateAccessChannelsPath = z.object({
  appInstanceId: z.string(),
})

/**
 * OK
 */
export const zAccessServiceUpdateAccessChannelsResponse = zUpdateAccessChannelsResponse

export const zAccessServiceGetAccessSettingsPath = z.object({
  appInstanceId: z.string(),
})

/**
 * OK
 */
export const zAccessServiceGetAccessSettingsResponse = zGetAccessSettingsResponse

export const zDeploymentServiceListDeploymentsPath = z.object({
  appInstanceId: z.string(),
})

export const zDeploymentServiceListDeploymentsQuery = z.object({
  pageNumber: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  resultsPerPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  environmentId: z.string().optional(),
})

/**
 * OK
 */
export const zDeploymentServiceListDeploymentsResponse = zListDeploymentsResponse

export const zAccessServiceGetDeveloperApiSettingsPath = z.object({
  appInstanceId: z.string(),
})

/**
 * OK
 */
export const zAccessServiceGetDeveloperApiSettingsResponse = zGetDeveloperApiSettingsResponse

export const zDeploymentServiceListEnvironmentDeploymentsPath = z.object({
  appInstanceId: z.string(),
})

/**
 * OK
 */
export const zDeploymentServiceListEnvironmentDeploymentsResponse =
  zListEnvironmentDeploymentsResponse

export const zAccessServiceGetAccessPolicyPath = z.object({
  appInstanceId: z.string(),
  environmentId: z.string(),
})

/**
 * OK
 */
export const zAccessServiceGetAccessPolicyResponse = zGetAccessPolicyResponse

export const zAccessServiceUpdateAccessPolicyBody = zUpdateAccessPolicyRequest

export const zAccessServiceUpdateAccessPolicyPath = z.object({
  appInstanceId: z.string(),
  environmentId: z.string(),
})

/**
 * OK
 */
export const zAccessServiceUpdateAccessPolicyResponse = zUpdateAccessPolicyResponse

export const zAccessServiceListApiKeysPath = z.object({
  appInstanceId: z.string(),
  environmentId: z.string(),
})

/**
 * OK
 */
export const zAccessServiceListApiKeysResponse = zListApiKeysResponse

export const zAccessServiceCreateApiKeyBody = zCreateApiKeyRequest

export const zAccessServiceCreateApiKeyPath = z.object({
  appInstanceId: z.string(),
  environmentId: z.string(),
})

/**
 * OK
 */
export const zAccessServiceCreateApiKeyResponse = zCreateApiKeyResponse

export const zAccessServiceDeleteApiKeyPath = z.object({
  appInstanceId: z.string(),
  environmentId: z.string(),
  apiKeyId: z.string(),
})

/**
 * OK
 */
export const zAccessServiceDeleteApiKeyResponse = zDeleteApiKeyResponse

export const zDeploymentServiceListRollbackTargetsPath = z.object({
  appInstanceId: z.string(),
  environmentId: z.string(),
})

export const zDeploymentServiceListRollbackTargetsQuery = z.object({
  pageNumber: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  resultsPerPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
})

/**
 * OK
 */
export const zDeploymentServiceListRollbackTargetsResponse = zListRollbackTargetsResponse

export const zDeploymentServiceCancelDeploymentBody = zCancelDeploymentRequest

export const zDeploymentServiceCancelDeploymentPath = z.object({
  appInstanceId: z.string(),
  environmentId: z.string(),
})

/**
 * OK
 */
export const zDeploymentServiceCancelDeploymentResponse = zCancelDeploymentResponse

export const zDeploymentServicePromoteBody = zPromoteRequest

export const zDeploymentServicePromotePath = z.object({
  appInstanceId: z.string(),
  environmentId: z.string(),
})

/**
 * OK
 */
export const zDeploymentServicePromoteResponse = zPromoteResponse

export const zDeploymentServiceRollbackBody = zRollbackRequest

export const zDeploymentServiceRollbackPath = z.object({
  appInstanceId: z.string(),
  environmentId: z.string(),
})

/**
 * OK
 */
export const zDeploymentServiceRollbackResponse = zRollbackResponse

export const zDeploymentServiceUndeployBody = zUndeployRequest

export const zDeploymentServiceUndeployPath = z.object({
  appInstanceId: z.string(),
  environmentId: z.string(),
})

/**
 * OK
 */
export const zDeploymentServiceUndeployResponse = zUndeployResponse

export const zReleaseServiceListReleaseSummariesPath = z.object({
  appInstanceId: z.string(),
})

export const zReleaseServiceListReleaseSummariesQuery = z.object({
  releaseId: z.string().optional(),
  displayName: z.string().optional(),
  pageNumber: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  resultsPerPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  environmentId: z.string().optional(),
})

/**
 * OK
 */
export const zReleaseServiceListReleaseSummariesResponse = zListReleaseSummariesResponse

export const zReleaseServiceListReleasesPath = z.object({
  appInstanceId: z.string(),
})

export const zReleaseServiceListReleasesQuery = z.object({
  releaseId: z.string().optional(),
  displayName: z.string().optional(),
  pageNumber: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  resultsPerPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  environmentId: z.string().optional(),
})

/**
 * OK
 */
export const zReleaseServiceListReleasesResponse = zListReleasesResponse

export const zReleaseServiceComputeReleaseDeploymentViewPath = z.object({
  appInstanceId: z.string(),
})

export const zReleaseServiceComputeReleaseDeploymentViewQuery = z.object({
  releaseId: z.string().optional(),
  environmentId: z.string().optional(),
})

/**
 * OK
 */
export const zReleaseServiceComputeReleaseDeploymentViewResponse =
  zComputeReleaseDeploymentViewResponse

export const zAppInstanceServiceGetAppInstanceOverviewPath = z.object({
  appInstanceId: z.string(),
})

/**
 * OK
 */
export const zAppInstanceServiceGetAppInstanceOverviewResponse = zGetAppInstanceOverviewResponse

export const zDeploymentServiceDeployBody = zDeployRequest

/**
 * OK
 */
export const zDeploymentServiceDeployResponse = zDeployResponse

export const zEnvironmentServiceListEnvironmentsQuery = z.object({
  environmentId: z.string().optional(),
  displayName: z.string().optional(),
  pageNumber: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  resultsPerPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
})

/**
 * OK
 */
export const zEnvironmentServiceListEnvironmentsResponse = zListEnvironmentsResponse

export const zReleaseServiceCreateReleaseBody = zCreateReleaseRequest

/**
 * OK
 */
export const zReleaseServiceCreateReleaseResponse = zCreateReleaseResponse

export const zReleaseServiceDeleteReleasePath = z.object({
  releaseId: z.string(),
})

/**
 * OK
 */
export const zReleaseServiceDeleteReleaseResponse = zDeleteReleaseResponse

export const zReleaseServiceGetReleasePath = z.object({
  releaseId: z.string(),
})

/**
 * OK
 */
export const zReleaseServiceGetReleaseResponse = zGetReleaseResponse

export const zReleaseServiceUpdateReleaseBody = zUpdateReleaseRequest

export const zReleaseServiceUpdateReleasePath = z.object({
  releaseId: z.string(),
})

/**
 * OK
 */
export const zReleaseServiceUpdateReleaseResponse = zUpdateReleaseResponse

export const zReleaseServiceExportReleaseDslPath = z.object({
  releaseId: z.string(),
})

/**
 * OK
 */
export const zReleaseServiceExportReleaseDslResponse = zExportReleaseDslResponse

export const zReleaseServiceListReleaseCredentialCandidatesPath = z.object({
  releaseId: z.string(),
})

/**
 * OK
 */
export const zReleaseServiceListReleaseCredentialCandidatesResponse =
  zListReleaseCredentialCandidatesResponse

export const zReleaseServiceComputeDeploymentOptionsBody = zComputeDeploymentOptionsRequest

/**
 * OK
 */
export const zReleaseServiceComputeDeploymentOptionsResponse = zComputeDeploymentOptionsResponse

export const zReleaseServicePrecheckReleaseBody = zPrecheckReleaseRequest

/**
 * OK
 */
export const zReleaseServicePrecheckReleaseResponse = zPrecheckReleaseResponse

/**
 * OK
 */
export const zConsoleSsoOAuth2LoginResponse = zOAuth2LoginReply

/**
 * OK
 */
export const zConsoleSsoOidcLoginResponse = zOidcReply

/**
 * OK
 */
export const zConsoleSsoSamlLoginResponse = zSamlLoginReply

export const zWebAppAuthGetWebAppAccessModeQuery = z.object({
  appId: z.string().optional(),
})

/**
 * OK
 */
export const zWebAppAuthGetWebAppAccessModeResponse = zGetWebAppAccessModeRes

export const zWebAppAuthUpdateWebAppWhitelistSubjectsBody = zUpdateWebAppWhitelistSubjectsReq

/**
 * OK
 */
export const zWebAppAuthUpdateWebAppWhitelistSubjectsResponse = zUpdateWebAppWhitelistSubjectsRes

export const zWebAppAuthSearchForWhilteListCandidatesQuery = z.object({
  keyword: z.string().optional(),
  pageNumber: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  resultsPerPage: z
    .int()
    .min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' })
    .max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })
    .optional(),
  groupId: z.string().optional(),
})

/**
 * OK
 */
export const zWebAppAuthSearchForWhilteListCandidatesResponse = zSearchForWhilteListCandidatesRes

export const zWebAppAuthGetWebAppWhitelistSubjectsQuery = z.object({
  appId: z.string().optional(),
})

/**
 * OK
 */
export const zWebAppAuthGetWebAppWhitelistSubjectsResponse = zGetWebAppWhitelistSubjectsRes

export const zWebAppAuthGetGroupSubjectsQuery = z.object({
  groupId: z.string().optional(),
})

/**
 * OK
 */
export const zWebAppAuthGetGroupSubjectsResponse = zGetGroupSubjectsRes

export const zWebAppAuthIsUserAllowedToAccessWebAppQuery = z.object({
  appId: z.string().optional(),
})

/**
 * OK
 */
export const zWebAppAuthIsUserAllowedToAccessWebAppResponse = zIsUserAllowedToAccessWebAppRes
