<?php

namespace App\Master\Http\Resources;

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

class CapVehicleView extends JsonResource
{
    public static $wrap = '';

    public function toArray(Request $request): array
    {
        return [
            'id' => $this->resource->id,
            'cap_code' => $this->resource->cap_code,
            'cap_id' => $this->resource->cap_id,
            'manufacturer' => $this->resource->manufacturer,
            'short_model' => $this->resource->short_model,
            'model' => $this->resource->model,
            'model_introduced' => $this->resource->model_introduced,
            'model_discontinued' => $this->resource->model_discontinued,
            'short_derivative' => $this->resource->short_derivative,
            'derivative' => $this->resource->derivative,
            'derivative_introduced_year' => $this->resource->derivative_introduced_year,
            'derivative_discontinued_year' => $this->resource->derivative_discontinued_year,
            'available_new_vehicle' => $this->resource->available_new_vehicle,
            'type' => $this->resource->type,
            'make_id' => $this->resource->make_id,
            'model_id' => $this->resource->model_id,
            'make' => $this->whenLoaded('make', fn () => [
                'id' => $this->resource->make->id,
                'name' => $this->resource->make->name,
            ]),
            'vehicle_model' => $this->whenLoaded('vehicleModel', fn () => [
                'id' => $this->resource->vehicleModel->id,
                'name' => $this->resource->vehicleModel->name,
            ]),
            'created_at' => $this->resource->created_at?->toISOString(),
            'updated_at' => $this->resource->updated_at?->toISOString(),
        ];
    }
}
