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

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

class BesoinDetailResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'reference' => $this->reference,
            'type_service' => $this->type_service instanceof \App\Enums\TypeService
                ? $this->type_service->value
                : $this->type_service,
            'type_service_label' => $this->type_service instanceof \App\Enums\TypeService
                ? $this->type_service->label()
                : $this->type_service,
            'type_situation' => $this->type_situation,
            'frequence' => $this->frequence,
            'taches_detaillees' => $this->taches_details,
            'age_souhaite' => $this->age_souhaite_min,
            'salaire_propose' => $this->salaire_propose,
            'telephone_contact' => $this->telephone_contact,
            'statut' => $this->statut instanceof \App\Enums\StatutBesoin
                ? $this->statut->value
                : $this->statut,
            'statut_label' => $this->statut instanceof \App\Enums\StatutBesoin
                ? $this->statut->label()
                : $this->statut,
            'ville' => [
                'id' => $this->ville->id,
                'nom' => $this->ville->nom,
            ],
            'quartier' => [
                'id' => $this->quartier->id,
                'nom' => $this->quartier->nom,
            ],
            'created_at' => $this->created_at->toISOString(),
            'updated_at' => $this->updated_at->toISOString(),
        ];
    }
}
