<?php

namespace App\Http\Resources;

use App\NotificationMaps\NotificationPayloadMapper;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Mtc\MercuryDataModels\Vehicle;

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

    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    #[\Override]
    public function toArray(Request $request): array
    {
        $data = parent::toArray($request);

        return array_merge($data, [
            'data_options' => [
                // Writable vehicle columns the inbound payload can be mapped onto.
                'available_fields' => collect((new Vehicle())->getFillable())
                    ->map(fn ($column) => ['id' => $column, 'name' => $column])
                    ->sortBy('name')
                    ->values(),
                'field_types' => collect(NotificationPayloadMapper::TYPES)
                    ->map(fn ($type) => ['id' => $type, 'name' => $type])
                    ->values(),
            ],
        ]);
    }
}
