<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Mtc\MercuryDataModels\Dealership;

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

    #[\Override]
    public function toArray(Request $request): array
    {
        return $this->resource->map(fn ($dealership) => $this->map($dealership))->toArray();
    }

    private function map(Dealership $dealership): array
    {
        return [
            'id' => $dealership->id,
            'name' => $dealership->name,
            'metaItems' => [
                'active' => $dealership->dealBuilderDeliveryConfig?->active ? 'Delivery active' : '',
            ],
            'has_config' => isset($dealership->dealBuilderDeliveryConfig->id),
        ];
    }
}
