<?php
namespace App\Exports;

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

class MissionsExport implements FromQuery, WithHeadings, WithMapping
{
    public function query()
    {
        return Mission::query()->with(['candidat', 'client']);
    }

    public function headings(): array
    {
        return [
            'Référence',
            'Candidat',
            'Client',
            'Statut',
            'Date début',
            'Date fin prévue',
        ];
    }

    public function map($mission): array
    {
        return [
            $mission->reference,
            $mission->candidat?->nom . ' ' . $mission->candidat?->prenom ?? '-',
            $mission->client?->nom_complet ?? '-',
            $mission->statut,
            $mission->date_debut?->format('d/m/Y') ?? '-',
            $mission->date_fin_prevue?->format('d/m/Y') ?? '-',
        ];
    }
}
