<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Mtc\MercuryDataModels\VehicleStandardEquipment;

class StandardEquipmentExport implements FromCollection, WithHeadings
{
    public function collection()
    {
        return VehicleStandardEquipment::query()
            ->distinct()
            ->select([
                'vehicle_standard_equipment.description',
                'filter_features.name as friendly_name',
                'vehicle_standard_equipment.category',
            ])
            ->leftJoin('filter_features', 'vehicle_standard_equipment.feature_id', '=', 'filter_features.id')
            ->whereNotNull('vehicle_standard_equipment.description')
            ->where('vehicle_standard_equipment.description', '!=', '')
            ->orderBy('vehicle_standard_equipment.description')
            ->get();
    }

    public function headings(): array
    {
        return ['description', 'friendly_name', 'category'];
    }
}
