<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreInfrastructureRequest;
use App\Http\Resources\InfrastructureResource;
use App\Models\Infrastructure;
use Illuminate\Http\Request;

class InfrastructureController extends Controller
{
    public function index()
    {
        $infrastructures = Infrastructure::all();
        return InfrastructureResource::collection($infrastructures);
    }

    public function store(StoreInfrastructureRequest $request)
    {
        $infrastructure = Infrastructure::create($request->validated());
        return new InfrastructureResource($infrastructure);
    }

    public function show(Infrastructure $infrastructure)
    {
        return new InfrastructureResource($infrastructure);
    }

    public function update(StoreInfrastructureRequest $request, Infrastructure $infrastructure)
    {
        $infrastructure->update($request->validated());
        return new InfrastructureResource($infrastructure);
    }

    public function destroy(Infrastructure $infrastructure)
    {
        $infrastructure->delete();
        return response()->json(['message' => 'Infrastructure supprimé'], 200);
    }
}
