<?php

namespace Modules\Lpj\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Modules\Lpj\Models\CustomField;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;

class CustomFieldExport implements WithColumnFormatting, WithHeadings, FromCollection, WithMapping
{
    public function collection()
    {
        return CustomField::all();
    }

    public function map($row): array
    {
        return [
            $row->id,
            $row->name,
            $row->type,
            $row->created_at,
            $row->updated_at,
        ];
    }

    public function headings(): array
    {
        return [
            'ID',
            'Name',
            'Type',
            'Created At',
            'Updated At',
        ];
    }

    public function columnFormats(): array
    {
        return [
            'A' => NumberFormat::FORMAT_NUMBER,
            'D' => NumberFormat::FORMAT_DATE_DDMMYYYY,
            'E' => NumberFormat::FORMAT_DATE_DDMMYYYY,
        ];
    }
}
