const { request } = require('../utils/request.js')

async function getActivityDetail({ activityId } = {}) {
  if (!activityId) {
    return {
      isError: true,
      content: [{ type: 'text', text: '缺少 activityId。请先调用 searchActivities 展示活动列表让用户选择。' }]
    }
  }

  const res = await request(`/ai/activities/${encodeURIComponent(activityId)}`, {
    method: 'GET',
    skillName: 'activity'
  })

  if (res.error) {
    return {
      isError: true,
      content: [{ type: 'text', text: res.safeMessage || '活动详情查询失败，请稍后重试。' }]
    }
  }

  const detail = res.data || {}
  return {
    isError: false,
    content: [{ type: 'text', text: `已加载活动「${detail.title || '活动'}」详情。` }],
    structuredContent: detail,
    _meta: {
      coverUrl: detail.coverUrl,
      relatedPage: detail.relatedPage || `/pages/activity-detail/index?id=${encodeURIComponent(activityId)}`
    }
  }
}

module.exports = getActivityDetail
