<?php

namespace App\Http\Resources;

use App\Country;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

/**
 * @property mixed id
 * @property mixed name
 * @property mixed country_id
 */
class CityResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $countryName = $this->country_id ? Country::withDescription($this->country_id)->name : null;
        return [
            'id' => $this->id,
            'country_id' => $this->country_id,
            'country_name' => $countryName,
            'name' => $this->name
        ];
    }
}
