<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;

use App\Http\Requests\StorePoleRequest;
use App\Http\Resources\PoleResource;
use App\Models\Pole;
use Illuminate\Http\Request;

class PoleController extends Controller
{ public function index()
    {
        $poles = Pole::all();
        return PoleResource::collection($poles);
    }

    public function store(StorePoleRequest $request)
    {   // Validation
       
        $pole = Pole::create($request->validated());
        return (new PoleResource($pole))
            ->additional(['message' => 'Créé avec succès']);
    }

    public function show(Pole $pole)
    {
        return new PoleResource($pole);
    }

    public function update(StorePoleRequest $request, Pole $pole)
    {
        $pole->update($request->validated());
        return new PoleResource($pole);
    }

    public function destroy(Pole $pole)
    {
        $pole->delete();
        return response()->json(['message' => 'Pôle supprimé'], 200);
    }

}
