<?php

namespace App\Http\Resources;

use App\Classes\Modules\ServiceTypes\Services\FetchesServiceConfigurations;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Models\ServiceType;
use Illuminate\Http\Resources\Json\JsonResource;

class CustomServiceTypeResource extends JsonResource
{

    /**
     * @param \Illuminate\Http\Request $request
     * @return array
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function toArray($request)
    {
        return [
            'id' => $this->detail->id,
            'name' => ServiceType::where('id', $this->detail->id)->first()->name,
            'detail' => $this->detail,
            'configurations' => (App()->make(FetchesServiceConfigurations::class))->execute($this->resource, SegmentConstants::CUSTOM_SERVICE_TYPE)
        ];
    }
}
