<?php

namespace App\Http\Resources;

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

class ServiceTypeResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function toArray($request)
    {

        $constants = SegmentConstant::where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->id', $this->id)->first();
        return [
            'id' => $this->id,
            'status' => (int) $this->status,
            'name' => $this->name,
            'configurations' => (App()->make(FetchesServiceConfigurations::class))->execute($constants, SegmentConstants::SERVICE_TYPE)
        ];

    }
}
