const { apiError, apiSuccess, requestAssist } = require('./requestAssist.js')

async function searchServices({ keyword = '' } = {}) {
  try {
    const text = String(keyword || '').trim()
    if (!text) {
      return {
        isError: true,
        content: [{ type: 'text', text: '缺少搜索关键词。请反问用户想查找哪类服务，禁止使用空关键词兜底搜索。' }],
      }
    }
    const result = await requestAssist({
      intent: 'searchServices',
      keyword: text,
      message: text,
    })
    return apiSuccess(result, result.reply || `已搜索“${text}”相关服务。`)
  } catch (error) {
    return apiError(error, '服务搜索失败')
  }
}

module.exports = searchServices
