<?php

declare(strict_types=1);

namespace App\Repositories\QzTrayLog;

use App\Models\QzTrayLog;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;

class QzTrayLogRepository implements QzTrayLogRepositoryInterface
{
    /**
     * Create a new log entry.
     */
    public function log(array $data): QzTrayLog
    {
        return QzTrayLog::create($data);
    }

    /**
     * Get recent logs.
     */
    public function getRecent(int $limit = 10): Collection
    {
        return QzTrayLog::with('user')
            ->orderBy('id', 'desc')
            ->limit($limit)
            ->get();
    }

    /**
     * Get paginated logs.
     */
    public function getPaginated(int $perPage = 15): LengthAwarePaginator
    {
        return QzTrayLog::with('user')
            ->orderBy('id', 'desc')
            ->paginate($perPage);
    }
}
