<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\CaseFile;
use App\Models\Client;
use App\Models\Consent;
use App\Models\Evidence;
use App\Services\ActivityLogger;
use Illuminate\Http\Request;
class TrashController extends Controller
{
    public function index()
    {
        return view('admin.trash.index', [
            'clients' => Client::onlyTrashed()->latest()->get(),
            'cases' => CaseFile::onlyTrashed()->latest()->get(),
            'consents' => Consent::onlyTrashed()->latest()->get(),
            'evidences' => Evidence::onlyTrashed()->latest()->get(),
        ]);
    }
    public function restoreClient(Request $request, int $id)
    {
        $client = Client::onlyTrashed()->findOrFail($id);
        $client->restore();
        ActivityLogger::log(auth()->id(), 'clients', 'restore', Client::class, $client->id, 'Cliente restaurado', $request->ip(), $request->userAgent());
        return redirect()->route('admin.trash.index');
    }
    public function restoreCase(Request $request, int $id)
    {
        $case = CaseFile::onlyTrashed()->findOrFail($id);
        $case->restore();
        ActivityLogger::log(auth()->id(), 'cases', 'restore', CaseFile::class, $case->id, 'Caso restaurado', $request->ip(), $request->userAgent());
        return redirect()->route('admin.trash.index');
    }
    public function restoreConsent(Request $request, int $id)
    {
        $consent = Consent::onlyTrashed()->findOrFail($id);
        $consent->restore();
        ActivityLogger::log(auth()->id(), 'consents', 'restore', Consent::class, $consent->id, 'Consentimento restaurado', $request->ip(), $request->userAgent());
        return redirect()->route('admin.trash.index');
    }
    public function restoreEvidence(Request $request, int $id)
    {
        $evidence = Evidence::onlyTrashed()->findOrFail($id);
        $evidence->restore();
        ActivityLogger::log(auth()->id(), 'evidences', 'restore', Evidence::class, $evidence->id, 'Evidência restaurada', $request->ip(), $request->userAgent());
        return redirect()->route('admin.trash.index');
    }
}
