<?php

namespace App\Http\Resources;

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

class CandidatAdminResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'user_id' => $this->user_id,
            'reference' => $this->reference,
            'nom' => $this->nom,
            'prenom' => $this->prenom,
            'nom_complet' => $this->nom_complet,
            'age' => $this->age,
            'date_naissance' => $this->date_naissance?->toISOString(),
            'sexe' => $this->sexe,
            'nationalite' => $this->nationalite,
            'numero_cni' => $this->numero_cni,
            'telephone' => $this->telephone,
            'type_situation' => $this->type_situation,
            'disponibilite' => $this->disponibilite,
            'statut' => $this->statut->value,
            'statut_label' => $this->statut->label(),
            'statut_casier_judiciaire' => $this->statut_casier_judiciaire,
            'adresse_domicile' => $this->adresse_domicile,
            'notes_internes' => $this->notes_internes,
            'forfait_paye_at' => $this->forfait_paye_at?->toISOString(),
            'formation_validee_at' => $this->formation_validee_at?->toISOString(),
            'ville' => $this->whenLoaded('ville', fn() => [
                'id' => $this->ville->id,
                'nom' => $this->ville->nom,
                'slug' => $this->ville->slug,
            ]),
            'quartier_domicile' => $this->whenLoaded('quartierDomicile', fn() => [
                'id' => $this->quartierDomicile->id,
                'nom' => $this->quartierDomicile->nom,
            ]),
            'parrain' => $this->whenLoaded('parrain', fn() => [
                'id' => $this->parrain->id,
                'nom_complet' => $this->parrain->nom_complet,
                'lien_avec_candidat' => $this->parrain->lien_avec_candidat,
                'telephone_principal' => $this->parrain->telephone_principal,
                'telephone_secondaire' => $this->parrain->telephone_secondaire,
                'email' => $this->parrain->email,
                'adresse_domicile' => $this->parrain->adresse_domicile,
                'a_signe_contrat' => $this->parrain->a_signe_contrat,
                'contrat_signe_at' => $this->parrain->contrat_signe_at?->toISOString(),
            ]),
            'pieces_jointes' => $this->whenLoaded('piecesJointes'),
            'formations' => $this->whenLoaded('formations'),
            'created_at' => $this->created_at->toISOString(),
            'updated_at' => $this->updated_at->toISOString(),
            'deleted_at' => $this->deleted_at?->toISOString(),
        ];
    }
}
