import { Router } from 'express';
import { authenticate } from '../../middleware/auth.middleware';
import { validate } from '../../middleware/validate';
import { analyticsService } from './analytics.service';
import { userDetailQuerySchema } from './analytics.schemas';

export const analyticsUserRouter = Router();
analyticsUserRouter.use(authenticate);

// GET /api/analytics/my-activity?days=30
analyticsUserRouter.get(
  '/my-activity',
  validate(userDetailQuerySchema, 'query'),
  async (req, res, next) => {
    try {
      const days = Number(req.query.days) || 30;
      const activity = await analyticsService.getMyActivity(req.user!.id, days);
      res.json(activity);
    } catch (err) {
      next(err);
    }
  },
);
