"""
Chat Threads
Retrieve chat threads in the workspace.
"""
name = "chat/threads"
version = "1.0.0"

"""
Get Threads
Retrieve list of threads from the whole workspace.
"""
usecase GetThreads {
  input  {
    """
    Workspace
    Identifier of a workspace, for example a Discord guild or a Slack workspace.
    """
    workspace! string!
  }

  result {
    """
    Threads
    List of retrieved threads
    """
    threads! [Thread]

    """
    Rate Limit
    Rate limit details.
    """
    rateLimit RateLimit
  }

  error Error

  example Successful {
    input {
      workspace = 'workspace_id'
    }

    result {
      threads = [
        {
          id = '1'
          createdAt = 1546167104000
          channel = 'random'
        },
        {
          id = '2'
          createdAt = 1546167105000
          channel = 'random'
        }
      ]
    }
  }

  example Failed {
    input {
      workspace = 'not-existing-workspace'
    }

    error {
      title = 'workspace_not_found'
    }
  }
}

model Thread {
  """
  Id
  Unique identifier of the thread
  """
  id! string!

  """
  Created At
  UNIX timestamp (in milliseconds, e.g. 1095379198750) when the thread was created
  """
  createdAt! number!

  """
  Channel
  Unique identifier of the channel where the thread is located
  """
  channel! string!

  """
  Archive At
  UNIX timestamp (in milliseconds, e.g. 1095379198750) when the thread will be archived
  Some providers limit the lifetime of threads and automatically archive them after some time period of inactivity.
  """
  archiveAt number!

  """
  Name
  Name of retrieved thread
  """
  name string

  """
  Members Count
  Number of users participating in the thread
  """
  membersCount number

  """
  Messages Count
  Number of messages in the retrieved thread
  """
  messagesCount number

  """
  Last Message At
  UNIX timestamp (in milliseconds, e.g. 1095379198750) when was the last message sent to thread.
  """
  lastMessageAt number
}   

model Error {
  """
  Title
  A short, human-readable summary of the problem type.
  """
  title!

  """
  Detail
  A human-readable explanation specific to this occurrence of the problem.
  """
  detail

  """
  Rate Limit
  Rate limit details.
  """
  rateLimit RateLimit
}

model RateLimit {
  """
  Bucket
  Different parts of API may have different rate limits.
  Bucket identifies to which part of API the rate limits apply.
  """
  bucket string

  """
  Total Requests
  Total requests available in the time window.
  """
  totalRequests number

  """
  Remaining Requests
  Remaining requests available in the time window.
  """
  remainingRequests number

  """
  Remaining Requests available in percents
  Remaining requests available in the time window in percents.
  """
  remainingRequestsPercentage number

  """
  Reset Timestamp
  Timestamp when the rate limits will reset (in Unix Timestamp ms format).
  """
  resetTimestamp number

  """
  Reset After
  Number of seconds until reset of rate limit
  """
  resetAfter number

  """
  Retry After
  Number of seconds until user can retry the request
  """
  retryAfter number
}