import Router from '@koa/router';
import { getInviteStats } from './invite.service';
import { authMiddleware } from '../../middleware/auth';

const router = new Router();

/**
 * 获取当前用户的邀请统计
 * GET /api/invite/stats
 */
router.get('/stats', authMiddleware, async (ctx) => {
  try {
    const userId = (ctx.state as any).user.id;
    const stats = await getInviteStats(parseInt(userId));

    ctx.body = {
      code: 0,
      message: 'success',
      data: stats,
    };
  } catch (error: any) {
    ctx.body = {
      code: 400,
      message: error.message || '获取邀请统计失败',
    };
  }
});

export default router;