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

async function getMyRegisteredActivities(args = {}) {
  const res = await request('/ai/me/registered-activities', {
    method: 'GET',
    data: {
      status: args.status || 'UPCOMING',
      limit: args.limit || 5
    },
    skillName: 'activity'
  })

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

  const data = res.data || {}
  const sourceItems = data.items || []
  return {
    isError: false,
    content: [{ type: 'text', text: `已找到 ${sourceItems.length} 条报名记录。` }],
    structuredContent: {
      items: sourceItems,
      total: data.total || sourceItems.length,
      hasMore: !!data.hasMore,
      listType: 'registered'
    },
    _meta: {
      viewItems: sourceItems,
      relatedPage: '/pages/my-registered-activities/index'
    }
  }
}

module.exports = getMyRegisteredActivities
