<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Shelf;
use Illuminate\Http\Request;
use Inertia\Inertia;
class ShelfController extends Controller
{
    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        $shelf = Shelf::get();
        return Inertia::render('Shelf/Shelf',compact('shelf'));
    }

    /**
     * Show the form for creating a new resource.
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $request->validate([
            'name' => 'required|unique:shelves,name',
        ]);
       
         Shelf::create($request->all());
        $shelf = Shelf::get();
        return response()->json(['message' => 'Shelf created successfully', 'shelf' => $shelf]);
    }

    /**
     * Display the specified resource.
     */
    public function show(string $id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     */
    public function edit(string $id)
    {

        

    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, string $id)
    {
        
        $shelf = Shelf::findOrFail($id);
        $shelf->update($request->all());
        $shelf = Shelf::get();
        return response()->json(['message' => 'Shelf updated successfully', 'shelf' => $shelf]);
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(string $id)
    {
        
        $shelf = Shelf::findOrFail($id);
        $shelf->delete();
        $shelf = Shelf::get();
        
        return response()->json(['message' => 'Shelf deleted successfully', 'shelf' => $shelf]);
    }
}
