<?php

namespace App\Http\Resources;

use App\City;
use App\ConsultingEvaluate;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @property mixed id
 * @property mixed status
 * @property mixed umrah_trip_date
 * @property mixed house_type
 * @property mixed rally_point_info
 * @property mixed escorts
 * @property mixed name
 * @property mixed email
 * @property mixed phone
 * @property mixed user_id
 * @property mixed umrah_trip_id
 * @property mixed departure_city
 * @property mixed arrival_city
 * @property mixed price_per_person
 * @property mixed person_count
 * @property mixed total
 * @property mixed umrahTrip
 */
class UmrahTripReservationResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $departure_city_name = $this->departure_city ? (City::withDescription(null, $this->departure_city)->name ?? null) : null;
        $arrival_city_name = $this->arrival_city ? (City::withDescription(null, $this->arrival_city)->name ?? null) : null;

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


        $rallyPointInfo = [];

        foreach ($this->rally_point_info as $name => $point) {
            $rallyPointInfo[] = [
                'name' => $name,
                'lat' => $point['lat'],
                'lng' => $point['lng'],
                'address' => $point['address'],
            ];
        }

        return [
            'id' => $this->id,
            'status' => $this->status,
            'umrah_trip' => UmrahTripResource::make($this->umrahTrip),
            'umrah_trip_date' =>$this->umrah_trip_date,
            'house_type' => __('umrahTrips.'.$this->house_type),
            'rally_point_info' => $rallyPointInfo,
            'escorts' => $this->escorts,
            'name' => $this->name,
            'email' => $this->email,
            'phone' => $this->phone,
            'user_id' => $this->user_id,
            'umrah_trip_id' => $this->umrah_trip_id,
            'departure_city' => $this->departure_city,
            'arrival_city' => $this->arrival_city,
            'departure_city_name' => $departure_city_name,
            'arrival_city_name' => $arrival_city_name,
            'person_price' => $this->price_per_person,
            'person_count' =>$this->person_count,
            'total' =>$this->total,
            'is_rated' => $evaluates ? true : false,
        ];
    }

}
