# ThinkWork Computer domain contracts.

enum ComputerStatus {
  ACTIVE
  PROVISIONING
  FAILED
  ARCHIVED
}

enum ComputerDesiredRuntimeStatus {
  RUNNING
  STOPPED
}

enum ComputerRuntimeStatus {
  PENDING
  STARTING
  RUNNING
  STOPPED
  FAILED
  UNKNOWN
}

enum ComputerScope {
  SHARED
  HISTORICAL_PERSONAL
}

enum ComputerAssignmentSubjectType {
  USER
  TEAM
}

enum ComputerAssignmentAccessSource {
  DIRECT
  TEAM
  BOTH
}

enum ComputerTaskStatus {
  PENDING
  RUNNING
  COMPLETED
  FAILED
  CANCELLED
}

enum ComputerTaskType {
  HEALTH_CHECK
  WORKSPACE_FILE_LIST
  WORKSPACE_FILE_READ
  WORKSPACE_FILE_WRITE
  WORKSPACE_FILE_DELETE
  THREAD_TURN
  GOOGLE_CLI_SMOKE
  GOOGLE_WORKSPACE_AUTH_CHECK
  GOOGLE_CALENDAR_UPCOMING
  RUNBOOK_EXECUTE
}

enum ComputerEventLevel {
  DEBUG
  INFO
  WARN
  ERROR
}

type Computer {
  id: ID!
  tenantId: ID!
  ownerUserId: ID
  owner: User
  sourceAgent: Agent
  name: String!
  slug: String!
  scope: ComputerScope!
  status: ComputerStatus!
  desiredRuntimeStatus: ComputerDesiredRuntimeStatus!
  runtimeStatus: ComputerRuntimeStatus!
  runtimeConfig: AWSJSON
  liveWorkspaceRoot: String
  efsAccessPointId: String
  ecsServiceName: String
  lastHeartbeatAt: AWSDateTime
  lastActiveAt: AWSDateTime
  budgetMonthlyCents: Int
  spentMonthlyCents: Int
  budgetPausedAt: AWSDateTime
  budgetPausedReason: String
  migratedFromAgentId: ID
  primaryAgentId: ID
  migrationMetadata: AWSJSON
  createdBy: ID
  createdAt: AWSDateTime!
  updatedAt: AWSDateTime!
}

type ComputerAssignment {
  id: ID!
  tenantId: ID!
  computerId: ID!
  computer: Computer
  subjectType: ComputerAssignmentSubjectType!
  userId: ID
  user: User
  teamId: ID
  team: Team
  role: String!
  assignedByUserId: ID
  assignedBy: User
  createdAt: AWSDateTime!
  updatedAt: AWSDateTime!
}

type ComputerAccessUser {
  userId: ID!
  user: User!
  accessSource: ComputerAssignmentAccessSource!
  directAssignment: ComputerAssignment
  teamAssignments: [ComputerAssignment!]!
  teams: [Team!]!
}

type UserComputerAssignment {
  computerId: ID!
  computer: Computer!
  accessSource: ComputerAssignmentAccessSource!
  directAssignment: ComputerAssignment
  teamAssignments: [ComputerAssignment!]!
  teams: [Team!]!
}

type ComputerTask {
  id: ID!
  tenantId: ID!
  computerId: ID!
  taskType: ComputerTaskType!
  status: ComputerTaskStatus!
  input: AWSJSON
  output: AWSJSON
  error: AWSJSON
  idempotencyKey: String
  claimedAt: AWSDateTime
  completedAt: AWSDateTime
  createdByUserId: ID
  createdAt: AWSDateTime!
  updatedAt: AWSDateTime!
}

type ComputerEvent {
  id: ID!
  tenantId: ID!
  computerId: ID!
  taskId: ID
  eventType: String!
  level: ComputerEventLevel!
  payload: AWSJSON
  createdAt: AWSDateTime!
}

input CreateComputerInput {
  tenantId: ID!
  name: String!
  slug: String
  scope: ComputerScope
  runtimeConfig: AWSJSON
  budgetMonthlyCents: Int
  migratedFromAgentId: ID
  primaryAgentId: ID
  migrationMetadata: AWSJSON
}

input ComputerAssignmentTargetInput {
  subjectType: ComputerAssignmentSubjectType!
  userId: ID
  teamId: ID
  role: String
}

input SetComputerAssignmentsInput {
  computerId: ID!
  assignments: [ComputerAssignmentTargetInput!]!
}

input SetUserComputerAssignmentsInput {
  userId: ID!
  computerIds: [ID!]!
  role: String
}

input UpdateComputerInput {
  name: String
  slug: String
  status: ComputerStatus
  desiredRuntimeStatus: ComputerDesiredRuntimeStatus
  runtimeStatus: ComputerRuntimeStatus
  runtimeConfig: AWSJSON
  liveWorkspaceRoot: String
  efsAccessPointId: String
  ecsServiceName: String
  lastHeartbeatAt: AWSDateTime
  lastActiveAt: AWSDateTime
  budgetMonthlyCents: Int
  spentMonthlyCents: Int
  budgetPausedReason: String
}

input EnqueueComputerTaskInput {
  computerId: ID!
  taskType: ComputerTaskType!
  input: AWSJSON
  idempotencyKey: String
}

extend type Query {
  myComputer: Computer
  assignedComputers: [Computer!]!
  computers(tenantId: ID!, status: ComputerStatus): [Computer!]!
  computer(id: ID!): Computer
  computerAssignments(computerId: ID!): [ComputerAssignment!]!
  computerAccessUsers(computerId: ID!): [ComputerAccessUser!]!
  userComputerAssignments(userId: ID!): [UserComputerAssignment!]!
  computerTasks(
    computerId: ID!
    threadId: ID
    status: ComputerTaskStatus
    limit: Int
  ): [ComputerTask!]!
  computerEvents(computerId: ID!, limit: Int): [ComputerEvent!]!
}

extend type Mutation {
  createComputer(input: CreateComputerInput!): Computer!
  updateComputer(id: ID!, input: UpdateComputerInput!): Computer!
  setComputerAssignments(
    input: SetComputerAssignmentsInput!
  ): [ComputerAssignment!]!
  setUserComputerAssignments(
    input: SetUserComputerAssignmentsInput!
  ): [ComputerAssignment!]!
  enqueueComputerTask(input: EnqueueComputerTaskInput!): ComputerTask!
}
