<?php

declare(strict_types=1);

namespace App\Http\Controllers\Market;

use App\Services\ActivityService;
use Hypervel\Http\Request;
use Hypervel\Support\Facades\Response;
use App\Http\Controllers\Helpers\ResponseHelper;

class ActivityController
{
    /**
     * Get recent activities.
     * 
     * @param Request $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function getRecent(Request $request)
    {
        $limit = (int) $request->input('limit', 10);
        $service = new ActivityService();
        $activities = $service->getRecentActivities($limit);
        
        return Response::json([
            'success' => true,
            'data' => $activities
        ]);
    }

    /**
     * Search activities.
     * 
     * @param Request $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function search(Request $request)
    {
        $query = $request->input('q', '');
        $limit = (int) $request->input('limit', 20);
        $service = new ActivityService();
        
        if (empty($query)) {
            $activities = $service->getRecentActivities($limit);
        } else {
            $activities = $service->searchActivities($query, $limit);
        }
        
        return Response::json([
            'success' => true,
            'data' => $activities
        ]);
    }
}
