<?php
namespace App\Http\Resources\Candidat;

use Illuminate\Http\Resources\Json\JsonResource;

class DossierCandidatResource extends JsonResource
{
    public function toArray($request): array
    {
        return [
            'id'                    => $this->id,
            'reference'             => $this->reference,
            'nom'                   => $this->nom,
            'prenom'                => $this->prenom,
            'nom_complet'           => $this->nom_complet, // Accessor
            'age'                   => $this->age,          // Accessor
            'date_naissance'        => $this->date_naissance?->toDateString(),
            'sexe'                  => $this->sexe,
            'nationalite'           => $this->nationalite,
            'telephone'             => $this->telephone,
            'type_situation'        => $this->type_situation,
            'disponibilite'         => $this->disponibilite,
            'adresse_domicile'      => $this->adresse_domicile,
            'ville'                 => $this->ville ? ['id' => $this->ville->id, 'nom' => $this->ville->nom] : null,
            'quartier'              => $this->quartierDomicile ? ['id' => $this->quartierDomicile->id, 'nom' => $this->quartierDomicile->nom] : null,
            'statut'                => [
                'valeur'    => $this->statut instanceof \App\Enums\StatutCandidat ? $this->statut->value : $this->statut,
                'label'     => $this->statut instanceof \App\Enums\StatutCandidat ? $this->statut->label() : $this->statut,
            ],
            'statut_casier_judiciaire' => $this->statut_casier_judiciaire,
            'dossier_complet'       => $this->dossierEstComplet(),
            'parrain'               => $this->whenLoaded('parrain', fn() => new ParrainResource($this->parrain)),
            'pieces_jointes'        => PieceJointeResource::collection($this->whenLoaded('piecesJointes')),
            'forfait_paye_at'       => $this->forfait_paye_at?->toISOString(),
            'formation_validee_at'  => $this->formation_validee_at?->toISOString(),
            'created_at'            => $this->created_at->toISOString(),
            'updated_at'            => $this->updated_at->toISOString(),
            // JAMAIS exposer : notes_internes, numero_cni
        ];
    }
}
