<?php

namespace App\Http\Resources;

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

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