<?php

namespace App\Domains\Catalog\Resources;

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

/**
 * @mixin \App\Domains\Catalog\Models\Attribute
 */
class AttributeResource extends JsonResource
{
    /**
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'codigo' => $this->codigo,
            'nombre' => $this->nombre,
            'is_required' => $this->is_required,
            'metadata_schema' => $this->metadata_schema,
            'type' => $this->type?->value ?? $this->type,
            'options' => AttributeOptionResource::collection($this->whenLoaded('options')),
        ];
    }
}
