<?php

namespace App\Http\Resources\PurchaseOrders;

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

class PurchaseOrderItemResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => (int) ($this->resource['id'] ?? 0),
            'purchase_order_id' => (int) ($this->resource['purchase_order_id'] ?? 0),
            'supply_id' => (int) ($this->resource['supply_id'] ?? 0),
            'supply_name' => $this->resource['supply_name'] ?? null,
            'supply_unit' => $this->resource['supply_unit'] ?? null,
            'description' => $this->resource['description'] ?? null,
            'quantity' => (int) ($this->resource['quantity'] ?? 0),
            'received_qty' => (int) ($this->resource['received_qty'] ?? 0),
            'unit_cost' => (float) ($this->resource['unit_cost'] ?? 0),
        ];
    }
}
