<?php

namespace App\Http\Resources;

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

class DestinationResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'nama_wisata' => $this->title,
            'slug' => $this->slug,
            'category' => [
                'id' => $this->kategori?->id,
                'name' => $this->kategori?->nama,
                'slug' => $this->kategori?->slug,
            ],
            'category_name' => $this->kategori?->nama,
            'location' => filled($this->location) && strtolower(trim($this->location)) !== 'lokasi'
                ? $this->location
                : 'Lumajang, Jawa Timur',
            'lokasi' => filled($this->location) && strtolower(trim($this->location)) !== 'lokasi'
                ? $this->location
                : 'Lumajang, Jawa Timur',
            'image' => $this->image,
            'image_url' => $this->fileUrl($this->image),
            'rating' => round((float) $this->rating, 1),
            'rating_label' => $this->rating_label,
            'distance' => $this->distance,
            'elevation' => $this->elevation,
            'tiket_parkir' => $this->tiket_parkir,
            'jam_operasional' => $this->jam_operasional,
            'short_description' => $this->short_description,
            'description' => $this->short_description,
            'overview' => $this->overview,
            'model_path' => $this->model_path,
            'model_url' => $this->fileUrl($this->model_path),
            'model_glb' => $this->fileUrl($this->model_path),
            'video_path' => $this->video_path,
            'video_url' => $this->fileUrl($this->video_path),
            'video' => $this->fileUrl($this->video_path),
            'is_video' => (bool) $this->is_video,
            'type' => $this->type,
            'show_ar_button' => filled($this->model_path),
            'show_video_player' => (bool) $this->is_video,
            'latitude' => $this->latitude !== null ? (float) $this->latitude : null,
            'longitude' => $this->longitude !== null ? (float) $this->longitude : null,
            'google_maps_url' => $this->google_maps_url,
            'created_at' => $this->created_at?->toISOString(),
            'updated_at' => $this->updated_at?->toISOString(),
        ];
    }
}
