<?php

namespace App\Http\Controllers;

use App\Http\Requests\CajaStoreRequest;
use App\Http\Requests\CajaUpdateRequest;
use App\Http\Resources\CajaCollection;
use App\Http\Resources\CajaResource;
use App\Models\Caja;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class CajaController extends Controller
{
    public function index(Request $request): CajaCollection
    {
        $cajas = Caja::all();

        return new CajaCollection($cajas);
    }

    public function store(CajaStoreRequest $request): CajaResource
    {
        $caja = Caja::create($request->validated());

        return new CajaResource($caja);
    }

    public function show(Request $request, Caja $caja): CajaResource
    {
        return new CajaResource($caja);
    }

    public function update(CajaUpdateRequest $request, Caja $caja): CajaResource
    {
        $caja->update($request->validated());

        return new CajaResource($caja);
    }

    public function destroy(Request $request, Caja $caja): Response
    {
        $caja->delete();

        return response()->noContent();
    }
}
