<?php

namespace Modules\Inventory\Transformers;

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

class ProductUnitConversionResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'product_id' => $this->product_id,
            'product' => $this->whenLoaded('product', function () {
                return $this->product;
            }),
            'from_unit_id' => $this->from_unit_id,
            'from_unit' => $this->whenLoaded('fromUnit', function () {
                return $this->fromUnit;
            }),
            'from_qty' => $this->from_qty,
            'to_unit_id' => $this->to_unit_id,
            'to_unit' => $this->whenLoaded('toUnit', function () {
                return $this->toUnit;
            }),
            'to_qty' => $this->to_qty,
            'is_purchase_unit' => $this->is_purchase_unit,
            'is_sale_unit' => $this->is_sale_unit,
            'is_default_purchase' => $this->is_default_purchase,
            'is_default_sale' => $this->is_default_sale,
            'status' => $this->status,
        ];
    }
}
