<?php

declare(strict_types=1);

namespace App\Http\Resources;

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

class ServiceResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'title' => $this->name,
            'excerpt' => $this->excerpt,
            'desc' => $this->desc,
            'description' => $this->desc,
            'price' => $this->price !== null ? (int) $this->price : null,
            'duration' => $this->duration,
            'type' => $this->type,
            'image' => $this->image ? url($this->image) : null,
            'gallery' => $this->gallery,
            'status' => $this->status,
            'is_active' => (bool) $this->is_active,
            'view_count' => $this->view_count,
            'category_id' => $this->category_id,
            'created_at' => $this->created_at?->toISOString(),
            'category' => new CategoryResource($this->whenLoaded('category')),
        ];
    }
}
