<?php

namespace App\Http\Controllers;

use App\Models\AuditLog;
use App\Services\Audit\AuditLogService;
use Illuminate\Http\Request;
use Illuminate\View\View;

class AuditLogController extends Controller
{
    public function __construct(
        private readonly AuditLogService $auditLogService,
    ) {}

    public function index(Request $request): View
    {
        $this->authorize('viewAny', AuditLog::class);

        return view('audit-logs.index', [
            'auditLogs' => $this->auditLogService->paginate($request->only([
                'action', 'user_id', 'subject_type', 'from', 'to',
            ])),
        ]);
    }

    public function show(AuditLog $auditLog): View
    {
        $this->authorize('view', $auditLog);

        return view('audit-logs.show', [
            'auditLog' => $auditLog->load('user'),
        ]);
    }
}
