<?php

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use App\Models\Devi;
use Illuminate\Http\Request;

class DeviController extends Controller
{
    public function index()
    {
        $devis = Devi::latest()->paginate(15);
        return view('dashboard.devis.index', compact('devis'));
    }

    public function show(Devi $devi)
    {
        return view('dashboard.devis.show', compact('devi'));
    }

    public function update(Request $request, Devi $devi)
    {
        $validated = $request->validate([
            'statut' => 'required|in:en_attente,en_cours,accepte,refuse',
            'notes_admin' => 'nullable|string',
        ]);

        $devi->update($validated);
        return redirect()->route('dashboard.devis.show', $devi)->with('success', 'Devis mis à jour.');
    }

    public function destroy(Devi $devi)
    {
        $devi->delete();
        return redirect()->route('dashboard.devis.index')->with('success', 'Devis supprimé.');
    }
}
