<?php

namespace App\Http\Resources;

use App\City;
use App\Helpers\ImageHelper;
use App\Hotel;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @property mixed id
 * @property mixed name
 * @property mixed city_id
 * @property mixed address
 * @property mixed lat
 * @property mixed lng
 * @property mixed email
 * @property mixed images
 * @property mixed room_type
 * @property mixed room_type_price
 * @property mixed added_service
 * @property mixed added_service_price
 * @property mixed include_breakfast
 * @property mixed status
 * @property mixed created_at
 * @property mixed deleted_at
 */
class HotelResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $images = is_string($this->images) ? json_decode($this->images, true) : $this->images;
        $images = array_map(function ($value){
            return ImageHelper::getFullPath($value);
        }, $images);
        $city = $this->city_id ? City::withDescription(null, $this->city_id)->name : null;
        $hotelName = descriptions(Hotel::find($this->id))->name;

        return [
            'id' => $this->id,
            'name' => $hotelName,
            'city_id' => $this->city_id,
            'city_name' => $city,
            'address' => $this->address,
            'lat' => $this->lat,
            'lng' => $this->lng,
            'email' => $this->email,
            'images' => $images,
            'room_type' => $this->room_type,
            'room_type_price' => $this->room_type_price,
            'added_service' => $this->added_service,
            'added_service_price' => $this->added_service_price,
            'include_breakfast' => $this->include_breakfast,
            'status' => $this->status,
            'created_at' => $this->created_at,
            'deleted_at' => $this->deleted_at,
        ];
    }
}
