<?php

namespace App\Http\Controllers;

use App\Http\Requests\ProveedorStoreRequest;
use App\Http\Requests\ProveedorUpdateRequest;
use App\Http\Resources\ProveedorCollection;
use App\Http\Resources\ProveedorResource;
use App\Models\Proveedor;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class ProveedorController extends Controller
{
    public function index(Request $request): ProveedorCollection
    {
        $proveedors = Proveedor::all();

        return new ProveedorCollection($proveedors);
    }

    public function store(ProveedorStoreRequest $request): ProveedorResource
    {
        $proveedor = Proveedor::create($request->validated());

        return new ProveedorResource($proveedor);
    }

    public function show(Request $request, Proveedor $proveedor): ProveedorResource
    {
        return new ProveedorResource($proveedor);
    }

    public function update(ProveedorUpdateRequest $request, Proveedor $proveedor): ProveedorResource
    {
        $proveedor->update($request->validated());

        return new ProveedorResource($proveedor);
    }

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

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