<?php

namespace App\Http\Resources;

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

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

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

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

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