<?php

namespace App\Http\Resources;

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

class StockLevelResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'branch_id' => $this->branch_id,
            'product_id' => $this->product_id,
            'variant_id' => $this->variant_id,
            'quantity' => $this->quantity,
            'reserved_quantity' => $this->reserved_quantity,
            'product' => $this->whenLoaded('product', fn () => $this->product?->only(['id', 'name', 'sku', 'barcode'])),
            'variant' => $this->whenLoaded('variant', fn () => $this->variant?->only(['id', 'name', 'sku', 'barcode'])),
        ];
    }
}
