<?php

namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreTypeInfrastructureRequest;
use App\Http\Resources\TypeInfrastructureResource;
use App\Models\TypeInfrastructure;
use Illuminate\Http\Request;

class TypeInfrastructureController extends Controller
{
    public function index()
    {
        $typeInfrastructures = TypeInfrastructure::all();
        return TypeInfrastructureResource::collection($typeInfrastructures);
    }

    public function store(StoreTypeInfrastructureRequest $request)
    {
        $typeInfrastructure = TypeInfrastructure::create($request->validated());
        return new TypeInfrastructureResource($typeInfrastructure);
    }

    public function show(TypeInfrastructure $typeInfrastructure)
    {
        return new TypeInfrastructureResource($typeInfrastructure);
    }

    public function update(StoreTypeInfrastructureRequest $request, TypeInfrastructure $typeInfrastructure)
    {
        $typeInfrastructure->update($request->validated());
        return new TypeInfrastructureResource($typeInfrastructure);
    }

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