<?php

namespace App\Exports;

use App\Models\Transaction;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class ExportTransactionReport implements FromCollection, WithHeadings, WithMapping
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return Transaction::searchable(['trx', 'user:username,system_id'])->filter([ 'remark', 'status'])->dateFilter()->orderBy('id', 'desc')->with('user')->get();
    }

    public function map($transaction): array
    {
        return [
            $transaction->user->system_id,
            $transaction->user->username,
            $transaction->trx,
            showDateTime($transaction->created_at),
            $transaction->amount,
            $transaction->payment_mode,
            $transaction->details,
        ];
    }

    public function headings(): array
    {
        return [
            'User Id',
            'User Name',
            'TRX',
            'Transacted',
            'Amount',
            'Mode Of Payment',
            'Details',
        ];
    }
}
