name = "chat/messages"
version = "1.0.0"

"""
Get chat messages
Retrieve paginated list of messages
"""
usecase GetMessages {
  input {
    """
    Destination
    Representation of a messaging destination. Can be ID or channel name, depending on the provider capability.
    """
    destination! string!
    
    """
    After Timestamp
    Retrieve only messages after the given UNIX timestamp (in seconds, e.g. 1095379198.75) 
    """
    afterTimestamp number
    
    """
    Before Timestamp
    Retrieve only messages before the given UNIX timestamp (in seconds, e.g. 1095379198.75)
    """
    beforeTimestamp number

    """
    Limit
    Maximum number of messages to retrieve in one page
    """
    limit number
    
    """
    Page
    Identification of page with paginated results (cursor)
    """
    page string!
  }
	
  result Messages
  error Error

  example Successful {
    input {
      destination = 'general',
      limit = 2
    }

    result {
      messages = [
        {
          id = '1'
          author = {
            id = 'U01'
            username = 'user1'
          },
          createdAt = 1643835553.658259,
          text = 'test 1'
        }
        {
          id = '2'
          author = {
            id = 'U02'
            username = 'user2'
          },
          createdAt = 1643835555.648069
          text = 'test 2'
        }
      ]
    }
  }

  example Failed {
    input {
      destination = 'not-existing',
    }

    error {
      title = 'channel_not_found'
    }
  }
}

model Attachment {
  """
  Id
  Unique identifier of the attachment
  """
  id! string!

  """
  Created At
  UNIX timestamp (e.g. 1095379198.75) when the attachment was created
  """
  createdAt! number!

  """
  File Name
  Name of attached file
  """
  fileName string

  """
  Media Type
  MIME type of the attached file
  """
  mediaType string

  """
  Url
  Source url of the attachment
  """
  url string
}

model Message {
  """
  Id
  Unique identifier of the message
  """
  id! string!

  """
  Author
  Author of retrieved message. Contains ID and username, depending on the provider capability.
  """
  author! {
    id! string!
    username string!
  }!

  """
  Created At
  UNIX timestamp (e.g. 1095379198.75) when the message was created
  """
  createdAt! number!

  """
  URL
  URL address pointing to retrieved message.
  """
  url string!

  """
  Has Thread
  Boolean that represents whether message is parent to some thread
  """
  hasThread boolean

  """
  Thread Id
  If the message was sent to a thread, identifies the parent thread by its Id.
  """
  threadId string

  """
  Text
  Contents of the retrieved message
  """
  text string

  """
  Updated At
  UNIX timestamp (e.g. 1095379198.75) when the message was last updated
  """
  updatedAt number

  """
  Reactions
  List of reactions on retrieved message. Each reaction contains emoji string containing encoded emoji,
  number of reactions and list of users (IDs or usernames, depending on the provider capability)
  """
  reactions [
    {
      emoji string
      count number
      users [string]
    }
  ]

  """
  Attachments
  List of attachments in retrieved message. Contains 
  """
  attachments [Attachment]
}

model Messages {
  """
  Messages
  List of retrieved messages
  """
  messages! [Message]!

  """
  Next Page
  Cursor to the next page for pagination forwards
  """
  nextPage string

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

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 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
}