<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class InfrastructureResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    { 
        return [
            'id' => $this->id,
            'nombre_movais' => $this->nombre_movais,
            'nombre_movais' => $this->nombre_moyens,
            'type_infrastructure' => [
                'id' => $this->type_infrastructure->id ?? null,
                'libelle' => $this->type_infrastructure->libelle ?? null,
            ],
            'annee' => [
                'id' => $this->annee->id ?? null,
                'libelle' => $this->annee->libelle ?? null,
            ],
            'etablissement' => [
                'id' => $this->etablissement->id ?? null,
                'libelle' => $this->etablissement->libelle ?? null,
            ],
            'created_at' => $this->created_at,
        ];
    }
}
