<?php

namespace Modules\LabCore\Http\Controllers;

use Illuminate\Routing\Controller;
use Modules\LabCore\Entities\LabCommunicationLog;

class LabLogController extends Controller
{
    public function index()
    {
        if (!auth()->user()->can('lab.view_logs')) {
            abort(403, 'Unauthorized action.');
        }

        $logs = LabCommunicationLog::latest('id')->paginate(50);

        return view('labCore::logs.index', compact('logs'));
    }

    public function clear()
    {
        if (!auth()->user()->can('lab.view_logs')) {
            abort(403, 'Unauthorized action.');
        }

        LabCommunicationLog::query()->delete();

        return redirect()->route('lab.logs.index')->with('status', [
            'success' => 1, 'msg' => 'Communication logs cleared.',
        ]);
    }
}
