<?php

namespace App\Http\Resources;

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

/**
 * @property mixed id
 * @property mixed name
 * @property mixed email
 * @property mixed phone
 * @property mixed babies_count
 * @property mixed children_count
 * @property mixed adult_count
 * @property mixed person_total
 * @property mixed trip_type
 * @property mixed going_date
 * @property mixed return_date
 * @property mixed trip_direction
 * @property mixed class_type
 * @property mixed departure_city
 * @property mixed arrival_city
 * @property mixed departure_airport
 * @property mixed arrival_airport
 */
class FlightResource 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;
        $arrival_city_name = $this->arrival_city ? City::withDescription(null, $this->arrival_city)->name : null;
        $departure_airport_name = $this->departure_airport ? Airport::withDescription(null, $this->departure_airport)->name : null;
        $arrival_airport_name = $this->arrival_airport ? Airport::withDescription(null, $this->arrival_airport)->name : null;

        return [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'phone' => $this->phone,
            'babies_count' => $this->babies_count,
            'children_count' =>$this->children_count,
            'adult_count' => $this->adult_count,
            'person_total' => $this->person_total,
            'trip_type' => __('flights.'.$this->trip_type),
            'going_date' => $this->going_date,
            'return_date' => $this->return_date,
            'trip_direction' => __('flights.'.$this->trip_direction),
            'class_type' => __('flights.'.$this->class_type),
            'departure_city' => $this->departure_city,
            'departure_city_name' => $departure_city_name,
            'arrival_city' => $this->arrival_city,
            'arrival_city_name' => $arrival_city_name,
            'departure_airport' =>$this->departure_city,
            'departure_airport_name' => $departure_airport_name,
            'arrival_airport' =>$this->arrival_city,
            'arrival_airport_name' => $arrival_airport_name,
        ];
    }
}
