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

async function getServiceDetail({ sourceType = '', id = '' } = {}) {
  try {
    const type = String(sourceType || '').trim()
    const serviceId = String(id || '').trim()
    if (!type || !serviceId) {
      return {
        isError: true,
        content: [{ type: 'text', text: '缺少 sourceType 或 id。禁止从用户自然语言猜测服务 ID，应先调用 recommendServices 或 searchServices 获取 cards[].id。' }],
      }
    }
    const result = await requestAssist({
      intent: 'getServiceDetail',
      sourceType: type,
      id: serviceId,
    })
    return apiSuccess(result, result.reply || '已加载服务详情。')
  } catch (error) {
    return apiError(error, '服务详情加载失败')
  }
}

module.exports = getServiceDetail
