<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class TransferReportExport implements FromCollection, WithHeadings, WithMapping
{
    protected $transfers;

    public function __construct($transfers)
    {
        $this->transfers = $transfers;
    }

    public function collection()
    {
        return $this->transfers;
    }

    public function headings(): array
    {
        return [
            'Item Name',
            'Warehouse',
            'Agent',
            'Quantity',
            'Unit Price',
            'Total Amount',
            'Date',
            'Notes'
        ];
    }

    public function map($transfer): array
    {
        return [
            $transfer->inventory->item_name,
            $transfer->warehouse->name,
            $transfer->agent->name,
            $transfer->quantity_transferred,
            $transfer->unit_price,
            $transfer->total_amount,
            $transfer->created_at->format('Y-m-d H:i:s'),
            $transfer->notes ?? '',
        ];
    }
}

