<?php

namespace App\Http\Resources;

use App\Models\RefrigeratorItem;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/** @mixin RefrigeratorItem */
class RefrigeratorItemResource extends JsonResource
{
    /** @return array<string, mixed> */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'category' => [
                'value' => $this->category->value,
                'label' => $this->category->label(),
            ],
            'quantity' => $this->quantity,
            'unit' => [
                'value' => $this->unit->value,
                'label' => $this->unit->label(),
            ],
            'weight_grams' => $this->getWeightInGrams(),
            'expiry_date' => $this->expiry_date?->toIso8601String(),
            'added_at' => $this->added_at?->toIso8601String(),
            'created_at' => $this->created_at?->toIso8601String(),
            'updated_at' => $this->updated_at?->toIso8601String(),
        ];
    }
}
