<?php

namespace App\Exports;

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

class InventoryExport implements FromCollection, WithHeadings, WithMapping
{
    public function collection()
    {
        return InventoryItem::all();
    }

    public function headings(): array
    {
        return [
            'Item Name',
            'Category',
            'Current Stock',
            'Minimum Stock',
            'Unit Price (UGX)',
            'Total Value (UGX)',
            'Supplier',
            'Status',
            'Last Updated'
        ];
    }

    public function map($item): array
    {
        return [
            $item->name,
            ucfirst($item->category),
            $item->quantity,
            $item->min_stock,
            number_format($item->unit_price, 0),
            number_format($item->total_value, 0),
            $item->supplier ?? 'N/A',
            ucfirst(str_replace('_', ' ', $item->stock_status)),
            $item->updated_at->format('Y-m-d H:i:s')
        ];
    }
}