<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class InvoiceItemResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'invoice_id' => $this->invoice_id,
            'name' => $this->name,
            'category' => $this->category,
            'subcategory' => $this->subcategory,
            'quantity' => (float) $this->quantity,
            'unit' => $this->unit,
            'unit_price' => (int) $this->unit_price,
            'total' => (int) $this->total,
            'description' => $this->description,
            'attachments' => $this->attachments,
            'created_at' => $this->created_at?->toISOString(),
            'updated_at' => $this->updated_at?->toISOString(),
        ];
    }
}
