<?php

namespace App\Http\Resources;

use App\Models\City;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Http\Resources\Json\JsonResource;

class CityResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id'         => $this->id,
            'name'       => $this->name,
            'state_id'   => $this->state_id,
            'country_id' => $this->country_id,
            'state'      => $this->state,
            'country'    => $this->country,
            'status'     => $this->status,
            'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i'),
            'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i'),
        ];
    }

    /**
     * @param  \Illuminate\Database\Eloquent\Collection<City>  $resource
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<CityResource>
     */
    public static function collection($resource): AnonymousResourceCollection
    {
        return parent::collection($resource);
    }
}
