<?php
namespace App\Exports;

use App\Models\Besoin;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class BesoinsExport implements FromQuery, WithHeadings, WithMapping
{
    public function query()
    {
        return Besoin::query()->with(['client', 'ville', 'quartier']);
    }

    public function headings(): array
    {
        return [
            'Référence',
            'Client',
            'Type service',
            'Statut',
            'Ville',
            'Quartier',
            'Date dépôt',
        ];
    }

    public function map($besoin): array
    {
        return [
            $besoin->reference,
            $besoin->client?->nom_complet ?? '-',
            $besoin->type_service?->value ?? '-',
            $besoin->statut,
            $besoin->ville?->nom ?? '-',
            $besoin->quartier?->nom ?? '-',
            $besoin->created_at->format('d/m/Y'),
        ];
    }
}
