import { Request, Response, NextFunction } from 'express';
import { OnboardingService } from '../../core/biz/OnboardingService';
import { EarlyStageBizService } from '../../core/biz/EarlyStageBizService';
import { logger } from '../../utils/logger';

/**
 * [UX_LITE_01] 极简控制台控制器 (Lite Console Controller)
 * @description 为初创 ToC 卖家设计的降级版交互接口。
 * 屏蔽复杂的 AGI 调优，仅保留：1. 核心任务进度 2. 一键刊登 3. 实时收入看板。
 */
export class LiteConsoleController {
  /**
   * 获取极简首页数据 (Summary Dashboard)
   */
  static async getSummary(req: Request, res: Response, next: NextFunction) {
    try {
      const { tenantId } = (req as any).traceContext;

      // 1. 获取新手任务进度
      const onboarding = await OnboardingService.getOnboardingSteps(tenantId);
      const pendingTasks = onboarding.filter(s => s.status !== 'COMPLETED').length;

      // 2. 获取核心经营数据 (Mock)
      const stats = {
        todaySales: 1250.50,
        todayOrders: 12,
        activePlatforms: ['Shopify', 'TikTok'],
        pendingListings: 5
      };

      // 3. 获取 AI 快捷建议 (轻量级)
      const quickTips = [
        '您的夏季风扇在 TikTok 流量激增，建议补货。',
        'Shopify 店铺有 3 个未付款订单，建议发送挽回邮件。'
      ];

      res.json({
        success: true,
        data: {
          onboardingProgress: `${onboarding.length - pendingTasks}/${onboarding.length}`,
          stats,
          quickTips,
          nextBestAction: onboarding.find(s => s.status === 'PENDING') || null
        }
      });
    } catch (err: any) {
      next(err);
    }
  }

  /**
   * 极简刊登历史
   */
  static async getListingHistory(req: Request, res: Response, next: NextFunction) {
    try {
      const { tenantId } = (req as any).traceContext;
      // 逻辑：从 cf_sync_status 查询最近 10 条
      res.json({ success: true, data: [] });
    } catch (err: any) {
      next(err);
    }
  }
}
