
# ----------------------------------------------------------
# LIST ALL (admin/debug)
# ----------------------------------------------------------
query listConversations(
  $offset: Int
  $limit: Int
) @auth(level: USER) {
  conversations(offset: $offset, limit: $limit, orderBy: { updatedAt: DESC }) {
    id
    subject
    status
    conversationType
    isGroup
    groupName
    lastMessage
    lastMessageAt
    createdAt
  }
}

# ----------------------------------------------------------
# GET BY ID
# ----------------------------------------------------------
query getConversationById($id: UUID!) @auth(level: USER) {
  conversation(id: $id) {
    id
    subject
    status
    conversationType
    isGroup
    groupName
    lastMessage
    lastMessageAt
    createdAt
  }
}

# ----------------------------------------------------------
# LIST BY TYPE (CLIENT_VENDOR / GROUP_STAFF)
# ----------------------------------------------------------
query listConversationsByType(
  $conversationType: ConversationType!
  $offset: Int
  $limit: Int
) @auth(level: USER) {
  conversations(
    where: { conversationType: { eq: $conversationType } }
    offset: $offset
    limit: $limit
    orderBy: { lastMessageAt: DESC }
  ) {
    id
    subject
    status
    conversationType
    isGroup
    groupName
    lastMessage
    lastMessageAt
    createdAt
  }
}

# ----------------------------------------------------------
# LIST BY STATUS (ACTIVE)
# ----------------------------------------------------------
query listConversationsByStatus(
  $status: ConversationStatus!
  $offset: Int
  $limit: Int
) @auth(level: USER) {
  conversations(
    where: { status: { eq: $status } }
    offset: $offset
    limit: $limit
    orderBy: { lastMessageAt: DESC }
  ) {
    id
    subject
    status
    conversationType
    isGroup
    groupName
    lastMessage
    lastMessageAt
    createdAt
  }
}

# ----------------------------------------------------------
# FILTER (dashboard/debug)
# Supports searching by multiple optional fields
# ----------------------------------------------------------
query filterConversations(
  $status: ConversationStatus
  $conversationType: ConversationType
  $isGroup: Boolean
  $lastMessageAfter: Timestamp
  $lastMessageBefore: Timestamp
  $offset: Int
  $limit: Int
) @auth(level: USER) {
  conversations(
    where: {
      status: { eq: $status }
      conversationType: { eq: $conversationType }
      isGroup: { eq: $isGroup }
      lastMessageAt: { ge: $lastMessageAfter, le: $lastMessageBefore }
    }
    offset: $offset
    limit: $limit
    orderBy: { lastMessageAt: DESC }
  ) {
    id
    subject
    status
    conversationType
    isGroup
    groupName
    lastMessage
    lastMessageAt
    createdAt
  }
}
