<?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
 * @property mixed user_id
 */
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) : null;
        $arrival_city_name = $this->arrival_city ? (City::withDescription(null, $this->arrival_city)->name ?? null) : null;
        $departure_airport_name = $this->departure_airport ? (Airport::withDescription(null, $this->departure_airport)->name ?? null) : null;
        $arrival_airport_name = $this->arrival_airport ? (Airport::withDescription(null, $this->arrival_airport)->name ?? null) : null;

        return [
            'id' => $this->id,
            'user_id' => $this->user_id,
            'name' => $this->name,
            'email' => $this->email,
            'phone' => $this->phone,
            'babies_count' => (int) $this->babies_count,
            'children_count' => (int) $this->children_count,
            'adult_count' => (int) $this->adult_count,
            'person_total' => (int) $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' => (int) $this->departure_city,
            'departure_city_name' => $departure_city_name,
            'arrival_city' => (int) $this->arrival_city,
            'arrival_city_name' => $arrival_city_name,
            'departure_airport' => (int) $this->departure_city,
            'departure_airport_name' => $departure_airport_name,
            'arrival_airport' => (int) $this->arrival_airport,
            'arrival_airport_name' => $arrival_airport_name,
        ];
    }
}
