<?php

namespace App\Http\Resources;

use App\Models\ClothingItem;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Storage;

/** @mixin ClothingItem */
class ClothingItemResource extends JsonResource
{
    /** @return array<string, mixed> */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'type' => [
                'value' => $this->type->value,
                'label' => $this->type->label(),
            ],
            'color' => $this->color,
            'season' => [
                'value' => $this->season->value,
                'label' => $this->season->label(),
            ],
            'occasion' => [
                'value' => $this->occasion->value,
                'label' => $this->occasion->label(),
            ],
            'image_path' => $this->image_path,
            'image_url' => $this->image_path ? Storage::url($this->image_path) : null,
            'brand' => $this->brand,
            'notes' => $this->notes,
            'created_at' => $this->created_at?->toIso8601String(),
            'updated_at' => $this->updated_at?->toIso8601String(),
        ];
    }
}
