<?php

namespace App\Http\Resources\PurchaseOrders;

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

class PurchaseOrderResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => (int) ($this->resource['id'] ?? 0),
            'po_number' => $this->resource['po_number'] ?? null,
            'supplier_id' => isset($this->resource['supplier_id']) ? (int) $this->resource['supplier_id'] : null,
            'supplier_name' => $this->resource['supplier_name'] ?? null,
            'status' => $this->resource['status'] ?? null,
            'order_date' => $this->resource['order_date'] ?? null,
            'expected_date' => $this->resource['expected_date'] ?? null,
            'subtotal' => (float) ($this->resource['subtotal'] ?? 0),
            'tax' => (float) ($this->resource['tax'] ?? 0),
            'total' => (float) ($this->resource['total'] ?? 0),
            'notes' => $this->resource['notes'] ?? null,
            'created_at' => $this->resource['created_at'] ?? null,
            'updated_at' => $this->resource['updated_at'] ?? null,
        ];
    }
}
