<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

class CategoryResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'name' => $this->title,
            'slug' => $this->slug,
            'desc' => $this->desc,
            'url' => $this->url,
            'icon' => $this->icon ? url($this->icon) : null,
            'image' => $this->icon ? url($this->icon) : null,
            'page_title' => $this->page_title,
            'meta_title' => $this->meta_title,
            'meta_desc' => $this->meta_desc,
            'meta_keywords' => $this->meta_keywords,
            'product_count' => $this->whenCounted('products'),
            'products_count' => $this->whenCounted('products'),
        ];
    }
}
