<?php

namespace App\Http\Resources;

use App\ConsultingEvaluate;
use App\Helpers\ImageHelper;
use App\Room;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @property mixed id
 * @property mixed status
 * @property mixed room_type
 * @property mixed days_count
 * @property mixed person_count
 * @property mixed going_date
 * @property mixed return_date
 * @property mixed added_service
 * @property mixed name
 * @property mixed email
 * @property mixed phone
 * @property mixed hotel_id
 * @property mixed city_id
 * @property mixed user_id
 * @property mixed hotel_email
 * @property mixed hotel_address
 * @property mixed hotel_image
 * @property mixed total
 * @property mixed added_service_price
 * @property mixed hotel
 */
class HotelReservationResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $addedServices = [];
//        $addedServicePrices = array_values(array_filter($this->added_service_price));
//        foreach ($this->added_service as $serviceKey => $service) {
//            $addedServices[] = ['name' => $service, 'price' => $addedServicePrices[$serviceKey]];
//        }

        $evaluates = ConsultingEvaluate::where('hotel_id', $this->hotel_id)->where('user_id', $this->user_id)->first();

//        $daysCountByDate = 0;
//        $goingDate = Carbon::make($this->going_date);
//        $returnDate = Carbon::make($this->return_date);

//        while ($goingDate < $returnDate){
//            $daysCountByDate++;
//            $returnDate = $returnDate->addDays(-1);
//        }

        return [
            'id' => $this->id,
            'status' => $this->status,
            'room_type' => $this->room_type,
            'days_count' => $this->days_count,
            'person_count' => $this->person_count,
            'going_date' => $this->going_date,
            'return_date' => $this->return_date,
            'days_count_by_date' => $this->days_count,
//            'added_service' => $addedServices,
//            'added_service_price' => $this->added_service_price,
            'name' => $this->name,
            'email' => $this->email,
            'phone' => $this->phone,
            'hotel_id' => $this->hotel_id,
            'city_id' => $this->city_id,
            'user_id' => $this->user_id,
            'hotel' => HotelResource::make($this->hotel),
            'hotel_name' => descriptions($this->hotel)->name,
            'hotel_email' => $this->hotel_email,
            'hotel_address' => $this->hotel_address,
            'hotel_image' => ImageHelper::getFullPath($this->hotel_image),
            'total' => $this->total,
            'is_rated' => $evaluates ? true : false,
        ];
    }
}
