<?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\Debiture;
    use Modules\Lpj\Models\Permohonan;
    use PhpOffice\PhpSpreadsheet\Style\NumberFormat;

    class PermohonanExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
    {
        public function collection()
        {
            return Permohonan::get();
        }

        public function map($row)
        : array
        {
            return [
                $row->id,
                $row->nomor_registrasi,
                $row->tanggal_permohonan,
                $row->user->name,
                $row->branch->name,
                $row->tujuanPenilaian->name,
                $row->debiture->name,
                $row->jenisFasilitasKredit->name,
                $row->nilaiPlafond->name,
                $row->status,
                $row->authorized_at,
                $row->authorized_status,
                $row->authorized_by,
                $row->created_at
            ];
        }

        public function headings()
        : array
        {
            return [
                'ID',
                'Nomor Registrasi',
                'Tanggal Permohonan',
                'User Pemohon',
                'Branch Pemohon',
                'Tujuan Penilaian',
                'Debitur',
                'Jenis Fasilitas Kredit',
                'Nilai Plafond',
                'Status Permohonan',
                'Tanggal Pengesahan',
                'Status Pengesahan',
                'Pengesah',
                'Tanggal Dibuat'
            ];
        }

        public function columnFormats()
        : array
        {
            return [
                'A' => NumberFormat::FORMAT_NUMBER,
                'C' => NumberFormat::FORMAT_DATE_DATETIME,
                'K' => NumberFormat::FORMAT_DATE_DATETIME,
                'N' => NumberFormat::FORMAT_DATE_DATETIME
            ];
        }
    }
