<?php

namespace App\Http\Resources;

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

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

    #[\Override]
    public function toArray(Request $request): array
    {
        $this->resource->load([
            'dealBuilderDeliveryConfig.upcomingHolidays',
        ]);
        $this->resource->setVisible(['id', 'name']);

        $config = $this->resource->dealBuilderDeliveryConfig?->toArray();
        $config['holidays'] = $this->resource->dealBuilderDeliveryConfig
            ?->upcomingHolidays
            ?->pluck('holiday_date') ?? [];

        return [
            'location' => $this->resource,
            'config' => $config,
        ];
    }
}
