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

import * as z from 'zod'

/**
 * AccountPayload
 */
export const zAccountPayload = z.object({
  email: z.string(),
  id: z.string(),
  name: z.string(),
})

/**
 * AppDescribeQuery
 *
 * `?fields=` allow-list for GET /apps/<id>/describe.
 *
 * Empty / omitted → all blocks. Unknown member → ValidationError → 422.
 */
export const zAppDescribeQuery = z.object({
  fields: z.array(z.string()).nullish(),
  workspace_id: z.string().nullish(),
})

/**
 * AppMode
 */
export const zAppMode = z.enum([
  'advanced-chat',
  'agent-chat',
  'channel',
  'chat',
  'completion',
  'rag-pipeline',
  'workflow',
])

/**
 * AppListQuery
 *
 * mode is a closed enum.
 */
export const zAppListQuery = z.object({
  limit: z.int().gte(1).lte(200).optional().default(20),
  mode: zAppMode.optional(),
  name: z.string().max(200).nullish(),
  page: z.int().gte(1).optional().default(1),
  tag: z.string().max(100).nullish(),
  workspace_id: z.string(),
})

/**
 * AppRunRequest
 */
export const zAppRunRequest = z.object({
  auto_generate_name: z.boolean().optional().default(true),
  conversation_id: z.string().nullish(),
  files: z.array(z.record(z.string(), z.unknown())).nullish(),
  inputs: z.record(z.string(), z.unknown()),
  query: z.string().nullish(),
  workflow_id: z.string().nullish(),
  workspace_id: z.string().nullish(),
})

/**
 * DeviceCodeRequest
 */
export const zDeviceCodeRequest = z.object({
  client_id: z.string(),
  device_label: z.string(),
})

/**
 * DeviceCodeResponse
 */
export const zDeviceCodeResponse = z.object({
  device_code: z.string(),
  expires_in: z.int(),
  interval: z.int(),
  user_code: z.string(),
  verification_uri: z.string(),
})

/**
 * DeviceLookupQuery
 */
export const zDeviceLookupQuery = z.object({
  user_code: z.string(),
})

/**
 * DeviceLookupResponse
 */
export const zDeviceLookupResponse = z.object({
  client_id: z.string().nullish(),
  expires_in_remaining: z.int().optional().default(0),
  valid: z.boolean(),
})

/**
 * DeviceMutateRequest
 */
export const zDeviceMutateRequest = z.object({
  user_code: z.string(),
})

/**
 * DeviceMutateResponse
 */
export const zDeviceMutateResponse = z.object({
  status: z.string(),
})

/**
 * DevicePollRequest
 */
export const zDevicePollRequest = z.object({
  client_id: z.string(),
  device_code: z.string(),
})

/**
 * FileResponse
 */
export const zFileResponse = z.object({
  conversation_id: z.string().nullish(),
  created_at: z.int().nullish(),
  created_by: z.string().nullish(),
  extension: z.string().nullish(),
  file_key: z.string().nullish(),
  id: z.string(),
  mime_type: z.string().nullish(),
  name: z.string(),
  original_url: z.string().nullish(),
  preview_url: z.string().nullish(),
  size: z.int(),
  source_url: z.string().nullish(),
  tenant_id: z.string().nullish(),
  user_id: z.string().nullish(),
})

export const zJsonValue = z.unknown()

/**
 * HumanInputFormSubmitPayload
 */
export const zHumanInputFormSubmitPayload = z.object({
  action: z.string(),
  inputs: z.record(z.string(), zJsonValue),
})

/**
 * MemberActionResponse
 */
export const zMemberActionResponse = z.object({
  result: z.string().optional().default('success'),
})

/**
 * MemberInvitePayload
 */
export const zMemberInvitePayload = z.object({
  email: z.string(),
  role: z.enum(['admin', 'normal']),
})

/**
 * MemberInviteResponse
 */
export const zMemberInviteResponse = z.object({
  email: z.string(),
  invite_url: z.string(),
  member_id: z.string(),
  result: z.string().optional().default('success'),
  role: z.string(),
  tenant_id: z.string(),
})

/**
 * MemberListQuery
 *
 * Strict (extra='forbid').
 */
export const zMemberListQuery = z.object({
  limit: z.int().gte(1).lte(200).optional().default(20),
  page: z.int().gte(1).optional().default(1),
})

/**
 * MemberResponse
 */
export const zMemberResponse = z.object({
  avatar: z.string().nullish(),
  email: z.string(),
  id: z.string(),
  name: z.string(),
  role: z.string(),
  status: z.string(),
})

/**
 * MemberListResponse
 */
export const zMemberListResponse = z.object({
  data: z.array(zMemberResponse),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * MemberRoleUpdatePayload
 */
export const zMemberRoleUpdatePayload = z.object({
  role: z.enum(['admin', 'normal']),
})

/**
 * PermittedExternalAppsListQuery
 *
 * Strict (extra='forbid').
 */
export const zPermittedExternalAppsListQuery = z.object({
  limit: z.int().gte(1).lte(200).optional().default(20),
  mode: zAppMode.optional(),
  name: z.string().max(200).nullish(),
  page: z.int().gte(1).optional().default(1),
})

/**
 * RevokeResponse
 */
export const zRevokeResponse = z.object({
  status: z.string(),
})

/**
 * ServerVersionResponse
 *
 * Meta endpoint payload for `GET /openapi/v1/_version` — no auth required.
 */
export const zServerVersionResponse = z.object({
  edition: z.enum(['CLOUD', 'SELF_HOSTED']),
  version: z.string(),
})

/**
 * SessionRow
 */
export const zSessionRow = z.object({
  client_id: z.string(),
  created_at: z.string().nullish(),
  device_label: z.string(),
  expires_at: z.string().nullish(),
  id: z.string(),
  last_used_at: z.string().nullish(),
  prefix: z.string(),
})

/**
 * SessionListResponse
 */
export const zSessionListResponse = z.object({
  data: z.array(zSessionRow),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * TagItem
 */
export const zTagItem = z.object({
  name: z.string(),
})

/**
 * AppDescribeInfo
 */
export const zAppDescribeInfo = z.object({
  author: z.string().nullish(),
  description: z.string().nullish(),
  id: z.string(),
  is_agent: z.boolean().optional().default(false),
  mode: z.string(),
  name: z.string(),
  service_api_enabled: z.boolean(),
  tags: z.array(zTagItem).optional().default([]),
  updated_at: z.string().nullish(),
})

/**
 * AppDescribeResponse
 */
export const zAppDescribeResponse = z.object({
  info: zAppDescribeInfo.optional(),
  input_schema: z.record(z.string(), z.unknown()).nullish(),
  parameters: z.record(z.string(), z.unknown()).nullish(),
})

/**
 * AppInfoResponse
 */
export const zAppInfoResponse = z.object({
  author: z.string().nullish(),
  description: z.string().nullish(),
  id: z.string(),
  mode: z.string(),
  name: z.string(),
  tags: z.array(zTagItem).optional().default([]),
})

/**
 * AppListRow
 */
export const zAppListRow = z.object({
  created_by_name: z.string().nullish(),
  description: z.string().nullish(),
  id: z.string(),
  mode: zAppMode,
  name: z.string(),
  tags: z.array(zTagItem).optional().default([]),
  updated_at: z.string().nullish(),
  workspace_id: z.string().nullish(),
  workspace_name: z.string().nullish(),
})

/**
 * AppListResponse
 */
export const zAppListResponse = z.object({
  data: z.array(zAppListRow),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * PermittedExternalAppsListResponse
 */
export const zPermittedExternalAppsListResponse = z.object({
  data: z.array(zAppListRow),
  has_more: z.boolean(),
  limit: z.int(),
  page: z.int(),
  total: z.int(),
})

/**
 * UsageInfo
 */
export const zUsageInfo = z.object({
  completion_tokens: z.int().optional().default(0),
  prompt_tokens: z.int().optional().default(0),
  total_tokens: z.int().optional().default(0),
})

/**
 * MessageMetadata
 */
export const zMessageMetadata = z.object({
  retriever_resources: z.array(z.record(z.string(), z.unknown())).optional().default([]),
  usage: zUsageInfo.optional(),
})

/**
 * WorkflowRunData
 */
export const zWorkflowRunData = z.object({
  created_at: z.int().nullish(),
  elapsed_time: z.number().nullish(),
  error: z.string().nullish(),
  finished_at: z.int().nullish(),
  id: z.string(),
  outputs: z.record(z.string(), z.unknown()).optional(),
  status: z.string(),
  total_steps: z.int().nullish(),
  total_tokens: z.int().nullish(),
  workflow_id: z.string(),
})

/**
 * WorkspaceDetailResponse
 */
export const zWorkspaceDetailResponse = z.object({
  created_at: z.string().nullish(),
  current: z.boolean(),
  id: z.string(),
  name: z.string(),
  role: z.string(),
  status: z.string(),
})

/**
 * WorkspacePayload
 */
export const zWorkspacePayload = z.object({
  id: z.string(),
  name: z.string(),
  role: z.string(),
})

/**
 * AccountResponse
 */
export const zAccountResponse = z.object({
  account: zAccountPayload.optional(),
  default_workspace_id: z.string().nullish(),
  subject_email: z.string().nullish(),
  subject_issuer: z.string().nullish(),
  subject_type: z.string(),
  workspaces: z.array(zWorkspacePayload).optional().default([]),
})

/**
 * WorkspaceSummaryResponse
 */
export const zWorkspaceSummaryResponse = z.object({
  current: z.boolean(),
  id: z.string(),
  name: z.string(),
  role: z.string(),
  status: z.string(),
})

/**
 * WorkspaceListResponse
 */
export const zWorkspaceListResponse = z.object({
  workspaces: z.array(zWorkspaceSummaryResponse),
})

/**
 * Success
 */
export const zGetHealthResponse = z.record(z.string(), z.unknown())

/**
 * Server version
 */
export const zGetVersionResponse = zServerVersionResponse

/**
 * Account info
 */
export const zGetAccountResponse = zAccountResponse

/**
 * Session list
 */
export const zGetAccountSessionsResponse = zSessionListResponse

/**
 * Session revoked
 */
export const zDeleteAccountSessionsSelfResponse = zRevokeResponse

export const zDeleteAccountSessionsBySessionIdPath = z.object({
  session_id: z.string(),
})

/**
 * Session revoked
 */
export const zDeleteAccountSessionsBySessionIdResponse = zRevokeResponse

export const zGetAppsQuery = z.object({
  limit: z.int().gte(1).lte(200).optional().default(20),
  mode: z.string().optional(),
  name: z.string().max(200).optional(),
  page: z.int().gte(1).optional().default(1),
  tag: z.string().max(100).optional(),
  workspace_id: z.string(),
})

/**
 * App list
 */
export const zGetAppsResponse = zAppListResponse

export const zGetAppsByAppIdDescribePath = z.object({
  app_id: z.string(),
})

export const zGetAppsByAppIdDescribeQuery = z.object({
  fields: z.array(z.string()).optional(),
  workspace_id: z.string().optional(),
})

/**
 * App description
 */
export const zGetAppsByAppIdDescribeResponse = zAppDescribeResponse

export const zPostAppsByAppIdFilesUploadPath = z.object({
  app_id: z.string(),
})

/**
 * File uploaded successfully
 */
export const zPostAppsByAppIdFilesUploadResponse = zFileResponse

export const zGetAppsByAppIdFormHumanInputByFormTokenPath = z.object({
  app_id: z.string(),
  form_token: z.string(),
})

/**
 * Form definition
 */
export const zGetAppsByAppIdFormHumanInputByFormTokenResponse = z.record(z.string(), z.unknown())

export const zPostAppsByAppIdFormHumanInputByFormTokenBody = zHumanInputFormSubmitPayload

export const zPostAppsByAppIdFormHumanInputByFormTokenPath = z.object({
  app_id: z.string(),
  form_token: z.string(),
})

/**
 * Form submitted
 */
export const zPostAppsByAppIdFormHumanInputByFormTokenResponse = z.record(z.string(), z.unknown())

export const zPostAppsByAppIdRunBody = zAppRunRequest

export const zPostAppsByAppIdRunPath = z.object({
  app_id: z.string(),
})

/**
 * Run result (SSE stream)
 */
export const zPostAppsByAppIdRunResponse = z.record(z.string(), z.unknown())

export const zGetAppsByAppIdTasksByTaskIdEventsPath = z.object({
  app_id: z.string(),
  task_id: z.string(),
})

/**
 * SSE event stream
 */
export const zGetAppsByAppIdTasksByTaskIdEventsResponse = z.record(z.string(), z.unknown())

export const zPostAppsByAppIdTasksByTaskIdStopPath = z.object({
  app_id: z.string(),
  task_id: z.string(),
})

/**
 * Task stopped
 */
export const zPostAppsByAppIdTasksByTaskIdStopResponse = z.record(z.string(), z.unknown())

export const zPostOauthDeviceApproveBody = zDeviceMutateRequest

/**
 * Approved
 */
export const zPostOauthDeviceApproveResponse = zDeviceMutateResponse

export const zPostOauthDeviceCodeBody = zDeviceCodeRequest

/**
 * Device code created
 */
export const zPostOauthDeviceCodeResponse = zDeviceCodeResponse

export const zPostOauthDeviceDenyBody = zDeviceMutateRequest

/**
 * Denied
 */
export const zPostOauthDeviceDenyResponse = zDeviceMutateResponse

export const zGetOauthDeviceLookupQuery = z.object({
  user_code: z.string(),
})

/**
 * Device lookup result
 */
export const zGetOauthDeviceLookupResponse = zDeviceLookupResponse

export const zPostOauthDeviceTokenBody = zDevicePollRequest

/**
 * Success
 */
export const zPostOauthDeviceTokenResponse = z.record(z.string(), z.unknown())

/**
 * Permitted external apps list
 */
export const zGetPermittedExternalAppsResponse = zPermittedExternalAppsListResponse

/**
 * Workspace list
 */
export const zGetWorkspacesResponse = zWorkspaceListResponse

export const zGetWorkspacesByWorkspaceIdPath = z.object({
  workspace_id: z.string(),
})

/**
 * Workspace detail
 */
export const zGetWorkspacesByWorkspaceIdResponse = zWorkspaceDetailResponse

export const zGetWorkspacesByWorkspaceIdMembersPath = z.object({
  workspace_id: z.string(),
})

export const zGetWorkspacesByWorkspaceIdMembersQuery = z.object({
  limit: z.int().gte(1).lte(200).optional().default(20),
  page: z.int().gte(1).optional().default(1),
})

/**
 * Member list
 */
export const zGetWorkspacesByWorkspaceIdMembersResponse = zMemberListResponse

export const zPostWorkspacesByWorkspaceIdMembersBody = zMemberInvitePayload

export const zPostWorkspacesByWorkspaceIdMembersPath = z.object({
  workspace_id: z.string(),
})

/**
 * Member invited
 */
export const zPostWorkspacesByWorkspaceIdMembersResponse = zMemberInviteResponse

export const zDeleteWorkspacesByWorkspaceIdMembersByMemberIdPath = z.object({
  member_id: z.string(),
  workspace_id: z.string(),
})

/**
 * Member removed
 */
export const zDeleteWorkspacesByWorkspaceIdMembersByMemberIdResponse = zMemberActionResponse

export const zPutWorkspacesByWorkspaceIdMembersByMemberIdRoleBody = zMemberRoleUpdatePayload

export const zPutWorkspacesByWorkspaceIdMembersByMemberIdRolePath = z.object({
  member_id: z.string(),
  workspace_id: z.string(),
})

/**
 * Role updated
 */
export const zPutWorkspacesByWorkspaceIdMembersByMemberIdRoleResponse = zMemberActionResponse

export const zPostWorkspacesByWorkspaceIdSwitchPath = z.object({
  workspace_id: z.string(),
})

/**
 * Workspace detail
 */
export const zPostWorkspacesByWorkspaceIdSwitchResponse = zWorkspaceDetailResponse
