import { apiRequest } from './api.js'

function buildQuery(params = {}) {
  const search = new URLSearchParams()
  if (params.agent) {
    search.set('agent', String(params.agent).trim())
  }
  if (params.sessionType || params.session_type) {
    search.set('session_type', String(params.sessionType || params.session_type).trim())
  }
  if (params.limit) {
    search.set('limit', String(params.limit))
  }
  const query = search.toString()
  return query ? `?${query}` : ''
}

export function createOperationFeedback(payload) {
  return apiRequest('/agent-feedback', {
    method: 'POST',
    body: JSON.stringify(payload || {})
  })
}

export function fetchOperationFeedbackSummary(params = {}) {
  return apiRequest(`/agent-feedback/summary${buildQuery(params)}`)
}
