type Query {

    me: User!

    """ Get user by ID """
    user (userId: ID!): User

    """ Get users """
    users (
        offset: Int! = 0,
        limit: Int! = 10,
        orderBy: USER_ORDER_KEYS! = id,
        orderDir: ORDER_DIR! = ASC,
        searchTerm: String,
        """ The minimum creation date/time like "2020-04-20T12:09:02.490Z" (inclusive). """
        minCreationDate: String,
        """ The maximum creation date/time like "2020-04-20T12:09:02.490Z" (exclusive). """
        maxCreationDate: String
    ): UserPaginationResult

    """ Get the number of users """
    userCount: Int!

    """ Get workspaces """
    workspaces (
        offset: Int! = 0,
        limit: Int! = 10,
        orderBy: WORKSPACE_ORDER_KEYS! = id,
        orderDir: ORDER_DIR! = ASC,
        ownerId: String,
        searchTerm: String,
        """ The minimum creation date/time like "2020-04-20T12:09:02.490Z" (inclusive). """
        minCreationTime: String,
        """ The maximum creation date/time like "2020-04-20T12:09:02.490Z" (exclusive). """
        maxCreationTime: String,
        type: WORKSPACE_TYPE,
    ): WorkspacePaginationResult

    """ Get workspace instances """
    workspaceInstances (
        offset: Int! = 0,
        limit: Int! = 10,
        orderBy: WORKSPACE_INSTANCE_ORDER_KEYS! = id,
        orderDir: ORDER_DIR! = ASC,
        ownerId: String,
        """ The minimum creation date/time like "2020-04-20T12:09:02.490Z" (inclusive). """
        minCreationTime: String,
        """ The maximum creation date/time like "2020-04-20T12:09:02.490Z" (exclusive). """
        maxCreationTime: String,
        onlyRunning: Boolean! = false,
        type: WORKSPACE_TYPE,
    ): WorkspaceInstancePaginationResult

}

# An object with a Globally Unique ID
interface Node {
  # The ID of the object.
  id: ID!
}

type User implements Node {
    id: ID!
    creationDate: String!
    avatarUrl: String
    name: String
    fullName: String
    displayName: String
    email: String
    blocked: Boolean
    deleted: Boolean
    workspaces: [Workspace!]!
}

type UserPaginationResult {
    total: Int!
    hasMore: Boolean!
    items: [User!]!
}

enum USER_ORDER_KEYS {
    id
    creationDate
}

type Workspace implements Node {

    """ Unique ID of this workspace """
    id: ID!

    """ Date/Time the workspace has been created """
    creationTime: String!

    """ The context URL of the workspace """
    contextURL: String!

    """ A description string """
    description: String!

    """ User that owns this workspace """
    owner: User!

    """ Workspace type """
    type: WORKSPACE_TYPE!

    """ Instances (sessions) of this workspace """
    instances: [WorkspaceInstance!]!
}

type WorkspacePaginationResult {
    total: Int!
    hasMore: Boolean!
    items: [Workspace!]!
}

enum WORKSPACE_ORDER_KEYS {
    id
    creationTime
}

""" WorkspaceInstance describes a part of a workspace's lifetime, specifically a single running session of it """
type WorkspaceInstance implements Node {

    """ ID is the unique identifier of this instance """
    id: ID!

    """the workspace this is an instance of"""
    workspace: Workspace

    """The time an instance has been created in the backend (before DB!)"""
    creationTime: String!

    """The time an instance has switched phase to 'Pending'"""
    deployedTime: String

    """The time an instance has switched phase to 'Running'"""
    startedTime: String

    """The time an instance has switched phase to 'Stopped'"""
    stoppedTime: String

    """ideUrl is the URL at which the workspace is available on the internet"""
    ideUrl: String!

    """region is the name of the workspace cluster this instance runs in"""
    region: String!

    """workspaceImage is the name of the Docker image this instance runs"""
    workspaceImage: String!

    """status is the latest status of the instance that we're aware of"""
    status: WorkspaceInstanceStatus!

    """instance is hard-deleted on the database and about to be collected by db-sync"""
    deleted: Boolean
}

type WorkspaceInstanceStatus {
    phase: String!
    conditions: WorkspaceInstanceConditions!
}

type WorkspaceInstanceConditions {
    """ Failed contains the reason the workspace failed to operate. If this field is empty, the workspace has not failed. """
    failed: String

    """ timeout contains the reason the workspace has timed out. If this field is empty, the workspace has not timed out. """
    timeout: String

    """ PullingImages marks if the workspace is currently pulling its images. This condition can only be set during PhaseCreating """
    pullingImages: Boolean

    """ ServiceExists denotes if the workspace theia-/ports- services exist. This condition will be true if either of the two services exist. """
    serviceExists: Boolean

    """ deployed marks that a workspace instance was sent/deployed at a workspace manager """
    deployed: Boolean

    """ Whether the workspace start triggered an image build """
    neededImageBuild: Boolean

    """ ISO8601 timestamp when the first user activity was registered in the frontend. Only set if the workspace is running. """
    firstUserActivity: String
}

type WorkspaceInstancePaginationResult {
    total: Int!
    hasMore: Boolean!
    items: [WorkspaceInstance!]!
}

enum WORKSPACE_TYPE {
    regular
    prebuild
    probe
}

enum WORKSPACE_INSTANCE_ORDER_KEYS {
    id
    creationTime
}

enum ORDER_DIR {
    ASC
    DESC
}

schema {
  query: Query
}
